diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java index 0cfe71a020167..45fb92b5644cb 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java @@ -398,48 +398,43 @@ static void configureJars(Project project) { ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties(); ext.set("licenseFile", null); ext.set("noticeFile", null); - project.getTasks() - .withType(Jar.class) - .configureEach( - jarTask -> { - // we put all our distributable files under distributions - jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions")); - // fixup the jar manifest - jarTask.doFirst( - t -> { - // this doFirst is added before the info plugin, therefore it will run - // after the doFirst added by the info plugin, and we can override attributes - jarTask.getManifest() - .attributes( - Map.of( - "Build-Date", - BuildParams.getBuildDate(), - "Build-Java-Version", - BuildParams.getCompilerJavaVersion() - ) - ); - } - ); - } - ); + project.getTasks().withType(Jar.class).configureEach(jarTask -> { + if (jarTask.isEnabled()) { + // we put all our distributable files under distributions + jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions")); + // fixup the jar manifest + jarTask.doFirst( + t -> { + // this doFirst is added before the info plugin, therefore it will run + // after the doFirst added by the info plugin, and we can override attributes + jarTask.getManifest() + .attributes( + Map.of("Build-Date", BuildParams.getBuildDate(), "Build-Java-Version", BuildParams.getCompilerJavaVersion()) + ); + } + ); + } + }); // add license/notice files project.afterEvaluate(p -> project.getTasks().withType(Jar.class).configureEach(jarTask -> { - File licenseFile = (File) ext.get("licenseFile"); - File noticeFile = (File) ext.get("noticeFile"); - if (licenseFile == null || noticeFile == null) { - throw new GradleException("Must specify license and notice file for project"); - } + if (jarTask.isEnabled()) { + File licenseFile = (File) ext.get("licenseFile"); + File noticeFile = (File) ext.get("noticeFile"); + if (licenseFile == null || noticeFile == null) { + throw new GradleException("Must specify license and notice file for project"); + } - jarTask.metaInf(spec -> { - spec.from(licenseFile.getParent(), from -> { - from.include(licenseFile.getName()); - from.rename(s -> "LICENSE.txt"); + jarTask.metaInf(spec -> { + spec.from(licenseFile.getParent(), from -> { + from.include(licenseFile.getName()); + from.rename(s -> "LICENSE.txt"); + }); + spec.from(noticeFile.getParent(), from -> { + from.include(noticeFile.getName()); + from.rename(s -> "NOTICE.txt"); + }); }); - spec.from(noticeFile.getParent(), from -> { - from.include(noticeFile.getName()); - from.rename(s -> "NOTICE.txt"); - }); - }); + } })); project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> { project.getTasks() diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/PublishPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/PublishPlugin.java index 857f5c7331694..23c16a7f8794d 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/PublishPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/PublishPlugin.java @@ -132,6 +132,7 @@ private static void configureJavadocJar(Project project) { project.getPlugins().withId("elasticsearch.java", p -> { TaskProvider javadocJarTask = project.getTasks().register("javadocJar", Jar.class); javadocJarTask.configure(jar -> { + jar.setEnabled(project.getTasks().getByName("jar").getEnabled()); jar.getArchiveClassifier().set("javadoc"); jar.setGroup("build"); jar.setDescription("Assembles a jar containing javadocs."); @@ -145,6 +146,7 @@ static void configureSourcesJar(Project project) { project.getPlugins().withId("elasticsearch.java", p -> { TaskProvider sourcesJarTask = project.getTasks().register("sourcesJar", Jar.class); sourcesJarTask.configure(jar -> { + jar.setEnabled(project.getTasks().getByName("jar").getEnabled()); jar.getArchiveClassifier().set("sources"); jar.setGroup("build"); jar.setDescription("Assembles a jar containing source files.");