From c87f6dd841c62360db22d202748da7e74ef5017e Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 23 May 2025 11:20:00 +0200 Subject: [PATCH 01/14] [Build] Investigate publishing to maven central --- .../internal/conventions/PublishPlugin.java | 6 +++ gradle/verification-metadata.xml | 50 +++++++++++++++++++ libs/cli/build.gradle | 19 +++++++ 3 files changed, 75 insertions(+) diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java index 22b0ab1918024..5ea4a63153042 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java @@ -27,6 +27,7 @@ import org.gradle.api.plugins.ExtensionContainer; import org.gradle.api.plugins.JavaLibraryPlugin; import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Provider; import org.gradle.api.provider.ProviderFactory; @@ -82,6 +83,11 @@ private void configurePublications(Project project) { publication.from(project.getComponents().getByName("java")); } }); + project.getPlugins().withType(JavaPlugin.class, plugin -> { + var javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); + javaPluginExtension.withJavadocJar(); + javaPluginExtension.withSourcesJar(); + }); @SuppressWarnings("unchecked") var projectLicenses = (MapProperty>) project.getExtensions().getExtraProperties().get("projectLicenses"); publication.getPom().withXml(xml -> { diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 566a640e9bd55..a612a7c9ee5a9 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -873,6 +873,16 @@ + + + + + + + + + + @@ -1068,6 +1078,11 @@ + + + + + @@ -1088,6 +1103,11 @@ + + + + + @@ -3991,21 +4011,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/cli/build.gradle b/libs/cli/build.gradle index d5b1bd6ac648e..252886a2f2814 100644 --- a/libs/cli/build.gradle +++ b/libs/cli/build.gradle @@ -6,9 +6,28 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ +plugins { + id("com.gradleup.nmcp").version("0.1.4") +} apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.publish' + +// Create your publications + +// Create your publications + +nmcp { + centralPortal { + username = "blubb" //TODO("Create a token username at https://central.sonatype.com/account") + password = "blubb" //TODO("Create a token password at https://central.sonatype.com/account") + // publish manually from the portal + publishingType = "USER_MANAGED" + // or if you want to publish automatically + publishingType = "AUTOMATIC" + } +} + dependencies { api 'net.sf.jopt-simple:jopt-simple:5.0.2' api project(':libs:core') From 959b5fbb8fafed95f7bafe71d0a1cc5d7f3b155b Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 23 May 2025 12:12:19 +0200 Subject: [PATCH 02/14] Aggregate publication --- build.gradle | 13 +++++++++++++ libs/cli/build.gradle | 20 +++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 7605eefc49b64..d6e78f90837f0 100644 --- a/build.gradle +++ b/build.gradle @@ -50,8 +50,21 @@ plugins { id 'elasticsearch.run-ccs' id 'elasticsearch.release-tools' id 'elasticsearch.versions' + id("com.gradleup.nmcp.aggregation").version("0.1.4") +} +version = VersionProperties.elasticsearch +nmcpAggregation { + centralPortal { + username = 'blubb' // TODO("Create a token username at https://central.sonatype.com/account") + password = 'blubb' // TODO("Create a token password at https://central.sonatype.com/account") + // publish manually from the portal + publishingType = "USER_MANAGED" + } } +dependencies { + nmcpAggregation(project(":libs:cli")) +} /** * This is a convenient method for declaring test artifact dependencies provided by the internal * test artifact plugin. It replaces basically the longer dependency notation with explicit capability diff --git a/libs/cli/build.gradle b/libs/cli/build.gradle index 252886a2f2814..e4b9a0a12c9c2 100644 --- a/libs/cli/build.gradle +++ b/libs/cli/build.gradle @@ -7,26 +7,12 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ plugins { - id("com.gradleup.nmcp").version("0.1.4") + id("com.gradleup.nmcp") } -apply plugin: 'elasticsearch.build' -apply plugin: 'elasticsearch.publish' - - -// Create your publications -// Create your publications -nmcp { - centralPortal { - username = "blubb" //TODO("Create a token username at https://central.sonatype.com/account") - password = "blubb" //TODO("Create a token password at https://central.sonatype.com/account") - // publish manually from the portal - publishingType = "USER_MANAGED" - // or if you want to publish automatically - publishingType = "AUTOMATIC" - } -} +apply plugin: 'elasticsearch.build' +apply plugin: 'elasticsearch.publish' dependencies { api 'net.sf.jopt-simple:jopt-simple:5.0.2' From 20982c38318f89fab437bfb954d8ddab1f247ffb Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Mon, 2 Jun 2025 16:59:27 +0200 Subject: [PATCH 03/14] Reference nmcp by version catalog --- build.gradle | 2 +- gradle/build.versions.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d6e78f90837f0..c427762f9600d 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ plugins { id 'elasticsearch.run-ccs' id 'elasticsearch.release-tools' id 'elasticsearch.versions' - id("com.gradleup.nmcp.aggregation").version("0.1.4") + alias(buildLibs.plugins.nmcp.aggregation) } version = VersionProperties.elasticsearch nmcpAggregation { diff --git a/gradle/build.versions.toml b/gradle/build.versions.toml index ae5dac9a29343..c38bbbaa04810 100644 --- a/gradle/build.versions.toml +++ b/gradle/build.versions.toml @@ -49,3 +49,4 @@ xmlunit-core = "org.xmlunit:xmlunit-core:2.8.2" [plugins] ospackage = { id = "com.netflix.nebula.ospackage-base", version = "11.11.2" } +nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version = "0.1.4" } From 09edc9dd82fa5d50158360e5fd2698c688554f01 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Tue, 3 Jun 2025 11:53:11 +0200 Subject: [PATCH 04/14] WIP --- build-conventions/build.gradle | 123 +++++++++++++++++---------------- build.gradle | 3 +- gradle/build.versions.toml | 1 + libs/cli/build.gradle | 2 +- 4 files changed, 66 insertions(+), 63 deletions(-) diff --git a/build-conventions/build.gradle b/build-conventions/build.gradle index b0eda5a34065a..9416c3028e8ee 100644 --- a/build-conventions/build.gradle +++ b/build-conventions/build.gradle @@ -17,88 +17,89 @@ buildscript { } plugins { - id 'java-gradle-plugin' - id 'java-test-fixtures' - id 'eclipse' + id 'java-gradle-plugin' + id 'java-test-fixtures' + id 'eclipse' } group = "org.elasticsearch" // This project contains Checkstyle rule implementations used by IDEs which use a Java 11 runtime java { - targetCompatibility = 11 - sourceCompatibility = 11 + targetCompatibility = 17 + sourceCompatibility = 17 } gradlePlugin { - // We already configure publication and we don't need or want the one that comes - // with the java-gradle-plugin - automatedPublishing = false - plugins { - internalLicenseheaders { - id = 'elasticsearch.internal-licenseheaders' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin' - } - eclipse { - id = 'elasticsearch.eclipse' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.EclipseConventionPlugin' - } - publish { - id = 'elasticsearch.publish' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.PublishPlugin' - } - licensing { - id = 'elasticsearch.licensing' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.LicensingPlugin' - } - buildTools { - id = 'elasticsearch.build-tools' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.BuildToolsConventionsPlugin' - } - versions { - id = 'elasticsearch.versions' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.VersionPropertiesPlugin' - } - formatting { - id = 'elasticsearch.formatting' - implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.FormattingPrecommitPlugin' - } + // We already configure publication and we don't need or want the one that comes + // with the java-gradle-plugin + automatedPublishing = false + plugins { + internalLicenseheaders { + id = 'elasticsearch.internal-licenseheaders' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin' } + eclipse { + id = 'elasticsearch.eclipse' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.EclipseConventionPlugin' + } + publish { + id = 'elasticsearch.publish' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.PublishPlugin' + } + licensing { + id = 'elasticsearch.licensing' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.LicensingPlugin' + } + buildTools { + id = 'elasticsearch.build-tools' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.BuildToolsConventionsPlugin' + } + versions { + id = 'elasticsearch.versions' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.VersionPropertiesPlugin' + } + formatting { + id = 'elasticsearch.formatting' + implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.FormattingPrecommitPlugin' + } + } } repositories { - mavenCentral() - gradlePluginPortal() + mavenCentral() + gradlePluginPortal() } dependencies { - api buildLibs.maven.model - api buildLibs.shadow.plugin - api buildLibs.apache.rat - compileOnly buildLibs.checkstyle - constraints { - api("org.eclipse.platform:org.eclipse.osgi:3.18.300") { - because("Use the same version as we do in spotless gradle plugin at runtime") - } - } - api(buildLibs.spotless.plugin) { - exclude module: "groovy-xml" + api buildLibs.maven.model + api buildLibs.shadow.plugin + api buildLibs.apache.rat + api buildLibs.nmcp + compileOnly buildLibs.checkstyle + constraints { + api("org.eclipse.platform:org.eclipse.osgi:3.18.300") { + because("Use the same version as we do in spotless gradle plugin at runtime") } + } + api(buildLibs.spotless.plugin) { + exclude module: "groovy-xml" + } } project.getPlugins().withType(JavaBasePlugin.class) { - java.getModularity().getInferModulePath().set(false); - eclipse.getClasspath().getFile().whenMerged { classpath -> - /* - * give each source folder a unique corresponding output folder - * outside of the usual `build` folder. We can't put the build - * in the usual build folder because eclipse becomes *very* sad - * if we delete it. Which `gradlew clean` does all the time. - */ - classpath.getEntries().findAll{ s -> s instanceof SourceFolder }.eachWithIndex { s, i -> - s.setOutput("out/eclipse" + i) - } + java.getModularity().getInferModulePath().set(false); + eclipse.getClasspath().getFile().whenMerged { classpath -> + /* + * give each source folder a unique corresponding output folder + * outside of the usual `build` folder. We can't put the build + * in the usual build folder because eclipse becomes *very* sad + * if we delete it. Which `gradlew clean` does all the time. + */ + classpath.getEntries().findAll { s -> s instanceof SourceFolder }.eachWithIndex { s, i -> + s.setOutput("out/eclipse" + i) } + } } tasks.withType(JavaCompile).configureEach { diff --git a/build.gradle b/build.gradle index c427762f9600d..abcaac12db7c7 100644 --- a/build.gradle +++ b/build.gradle @@ -50,8 +50,9 @@ plugins { id 'elasticsearch.run-ccs' id 'elasticsearch.release-tools' id 'elasticsearch.versions' - alias(buildLibs.plugins.nmcp.aggregation) + id 'com.gradleup.nmcp.aggregation' } + version = VersionProperties.elasticsearch nmcpAggregation { centralPortal { diff --git a/gradle/build.versions.toml b/gradle/build.versions.toml index c38bbbaa04810..6e15eebc63f66 100644 --- a/gradle/build.versions.toml +++ b/gradle/build.versions.toml @@ -36,6 +36,7 @@ junit5-platform-launcher = "org.junit.platform:junit-platform-launcher:1.8.1" junit5-vintage = { group = "org.junit.vintage", name="junit-vintage-engine", version.ref="junit5" } maven-model = "org.apache.maven:maven-model:3.6.2" mockito-core = "org.mockito:mockito-core:1.9.5" +nmcp = { group = "com.gradleup.nmcp", name = "nmcp", version = "0.1.4" } nebula-info = "com.netflix.nebula:gradle-info-plugin:11.3.3" reflections = "org.reflections:reflections:0.9.12" shadow-plugin = "com.gradleup.shadow:shadow-gradle-plugin:8.3.5" diff --git a/libs/cli/build.gradle b/libs/cli/build.gradle index e4b9a0a12c9c2..75589f974683c 100644 --- a/libs/cli/build.gradle +++ b/libs/cli/build.gradle @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ plugins { - id("com.gradleup.nmcp") +// id("com.gradleup.nmcp") } From 7a7b570ae7d2378a566d7b410b1d72d117d95b5f Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Tue, 3 Jun 2025 12:51:06 +0200 Subject: [PATCH 05/14] Publish all publishable projects by default --- .../gradle/internal/conventions/PublishPlugin.java | 3 +++ build.gradle | 10 +++++----- libs/cli/build.gradle | 5 ----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java index 5ea4a63153042..d3f03b9534be3 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java @@ -14,6 +14,8 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowExtension; import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin; +import nmcp.NmcpPlugin; + import org.elasticsearch.gradle.internal.conventions.info.GitInfo; import org.elasticsearch.gradle.internal.conventions.precommit.PomValidationPrecommitPlugin; import org.elasticsearch.gradle.internal.conventions.util.Util; @@ -66,6 +68,7 @@ public void apply(Project project) { project.getPluginManager().apply(MavenPublishPlugin.class); project.getPluginManager().apply(PomValidationPrecommitPlugin.class); project.getPluginManager().apply(LicensingPlugin.class); + project.getPluginManager().apply(NmcpPlugin.class); configureJavadocJar(project); configureSourcesJar(project); configurePomGeneration(project); diff --git a/build.gradle b/build.gradle index abcaac12db7c7..c2de0979e9b7a 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ plugins { id 'elasticsearch.internal-testclusters' id 'elasticsearch.run' id 'elasticsearch.run-ccs' + id 'elasticsearch.repositories' id 'elasticsearch.release-tools' id 'elasticsearch.versions' id 'com.gradleup.nmcp.aggregation' @@ -61,11 +62,10 @@ nmcpAggregation { // publish manually from the portal publishingType = "USER_MANAGED" } + // this breaks project isolation but this is broken in elasticsearch build atm anyhow. + publishAllProjectsProbablyBreakingProjectIsolation() } -dependencies { - nmcpAggregation(project(":libs:cli")) -} /** * This is a convenient method for declaring test artifact dependencies provided by the internal * test artifact plugin. It replaces basically the longer dependency notation with explicit capability @@ -309,7 +309,7 @@ allprojects { tasks.register('resolveAllDependencies', ResolveAllDependencies) { def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"] configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false } - if(project.path == ':') { + if (project.path == ':') { resolveJavaToolChain = true // ensure we have best possible caching of bwc builds @@ -334,7 +334,7 @@ allprojects { } ext.withReleaseBuild = { Closure config -> - if(buildParams.snapshotBuild == false) { + if (buildParams.snapshotBuild == false) { config.call() } } diff --git a/libs/cli/build.gradle b/libs/cli/build.gradle index 75589f974683c..d5b1bd6ac648e 100644 --- a/libs/cli/build.gradle +++ b/libs/cli/build.gradle @@ -6,11 +6,6 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ -plugins { -// id("com.gradleup.nmcp") -} - - apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.publish' From 49f0c478dcccc8bb76ae200d09908848045b8b7e Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Wed, 4 Jun 2025 08:32:33 +0200 Subject: [PATCH 06/14] WIP --- .../internal/PublishPluginFuncTest.groovy | 84 +++++++++++++++++++ .../fixtures/AbstractGradleFuncTest.groovy | 3 + 2 files changed, 87 insertions(+) diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy index cc551057cd600..99e41da030496 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy @@ -23,6 +23,90 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { configurationCacheCompatible = false } + def "project with plugin applied is considered for maven central publication"() { + given: + // required for JarHell to work + subProject(":libs:some-public-lib") << """ + plugins { + id 'elasticsearch.java' + id 'elasticsearch.publish' + } + """ + + buildFile << """ + plugins { + id 'com.gradleup.nmcp.aggregation' + } + + version = "1.0" + group = 'org.acme' + description = "custom project description" + nmcpAggregation { + centralPortal { + username = 'acme' + password = 'acmepassword' + // publish manually from the portal + publishingType = "USER_MANAGED" + } + // this breaks project isolation but this is broken in elasticsearch build atm anyhow. + publishAllProjectsProbablyBreakingProjectIsolation() + } + """ + + when: + def result = gradleRunner(':zipAggregation').build() + + then: + result.task(":zipAggregation").outcome == TaskOutcome.SUCCESS + file("build/nmcp/zip/aggregation.zip").exists() + zip("build/nmcp/zip/aggregation.zip").containsFile("hello-world-1.0.pom") + +// assertXmlEquals( +// file("build/distributions/hello-world-1.0.pom").text, """ +// +// +// +// +// +// +// 4.0.0 +// org.acme +// hello-world +// 1.0 +// hello-world +// custom project description +// unknown +// +// unknown +// +// 2009 +// +// +// Elastic License 2.0 +// https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/ELASTIC-LICENSE-2.0.txt +// repo +// +// +// GNU Affero General Public License Version 3 +// https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt +// repo +// +// +// Server Side Public License, v 1 +// https://www.mongodb.com/licensing/server-side-public-license +// repo +// +// +// +// +// Elastic +// https://www.elastic.co +// +// +//""" +// ) + } + def "artifacts and tweaked pom is published"() { given: buildFile << """ diff --git a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index 72d8134869037..f5bf0ef76ef25 100644 --- a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -234,6 +234,9 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3" (it as TestResultExtension.ErrorListener).errorInfo != null } } + void zip(String relativePath) { + } + static class ProjectConfigurer { private File projectDir From 970792c4b7d9d3add01e399781c547f5b0b160c4 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Wed, 4 Jun 2025 10:50:24 +0200 Subject: [PATCH 07/14] Add test coverage for aggregrationZip creation --- .../internal/PublishPluginFuncTest.groovy | 400 ++++++++++-------- .../fixtures/AbstractGradleFuncTest.groovy | 62 ++- 2 files changed, 295 insertions(+), 167 deletions(-) diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy index 99e41da030496..b561f0b05cfa5 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy @@ -31,6 +31,19 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { id 'elasticsearch.java' id 'elasticsearch.publish' } + + group = 'org.acme' + version = '1.0' + """ + + subProject(":libs:some-other-lib") << """ + plugins { + id 'elasticsearch.java' + id 'elasticsearch.publish' + } + + group = 'org.acme.xpack' + version = '1.0' """ buildFile << """ @@ -59,57 +72,111 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { then: result.task(":zipAggregation").outcome == TaskOutcome.SUCCESS file("build/nmcp/zip/aggregation.zip").exists() - zip("build/nmcp/zip/aggregation.zip").containsFile("hello-world-1.0.pom") - -// assertXmlEquals( -// file("build/distributions/hello-world-1.0.pom").text, """ -// -// -// -// -// -// -// 4.0.0 -// org.acme -// hello-world -// 1.0 -// hello-world -// custom project description -// unknown -// -// unknown -// -// 2009 -// -// -// Elastic License 2.0 -// https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/ELASTIC-LICENSE-2.0.txt -// repo -// -// -// GNU Affero General Public License Version 3 -// https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt -// repo -// -// -// Server Side Public License, v 1 -// https://www.mongodb.com/licensing/server-side-public-license -// repo -// -// -// -// -// Elastic -// https://www.elastic.co -// -// -//""" -// ) - } - def "artifacts and tweaked pom is published"() { - given: - buildFile << """ + + def zip = zip("build/nmcp/zip/aggregation.zip") + zip.files().findAll { it.isDirectory() == false }.collect { it.name }.sort() == [ + "org/acme/some-public-lib/1.0/some-public-lib-1.0-javadoc.jar", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-javadoc.jar.md5", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-javadoc.jar.sha1", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-javadoc.jar.sha256", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-javadoc.jar.sha512", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-sources.jar", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-sources.jar.md5", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-sources.jar.sha1", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-sources.jar.sha256", + "org/acme/some-public-lib/1.0/some-public-lib-1.0-sources.jar.sha512", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.jar", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.jar.md5", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.jar.sha1", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.jar.sha256", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.jar.sha512", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.module", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.module.md5", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.module.sha1", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.module.sha256", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.module.sha512", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.pom", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.pom.md5", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.pom.sha1", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.pom.sha256", + "org/acme/some-public-lib/1.0/some-public-lib-1.0.pom.sha512", + + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-javadoc.jar", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-javadoc.jar.md5", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-javadoc.jar.sha1", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-javadoc.jar.sha256", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-javadoc.jar.sha512", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-sources.jar", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-sources.jar.md5", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-sources.jar.sha1", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-sources.jar.sha256", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0-sources.jar.sha512", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.jar", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.jar.md5", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.jar.sha1", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.jar.sha256", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.jar.sha512", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.module", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.module.md5", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.module.sha1", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.module.sha256", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.module.sha512", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom.md5", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom.sha1", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom.sha256", + "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom.sha512" + ] + + assertXmlEquals(zip.file("org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom").read(),""" + + + + + + + 4.0.0 + org.acme.xpack + some-other-lib + 1.0 + some-other-lib + + unknown + + unknown + + 2009 + + + Elastic License 2.0 + https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/ELASTIC-LICENSE-2.0.txt + repo + + + GNU Affero General Public License Version 3 + https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt + repo + + + Server Side Public License, v 1 + https://www.mongodb.com/licensing/server-side-public-license + repo + + + + + Elastic + https://www.elastic.co + + + +""") +} + +def "artifacts and tweaked pom is published"() { + given: + buildFile << """ plugins { id 'elasticsearch.java' id 'elasticsearch.publish' @@ -120,17 +187,17 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { description = "custom project description" """ - when: - def result = gradleRunner('assemble').build() - - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-1.0.jar").exists() - file("build/distributions/hello-world-1.0-javadoc.jar").exists() - file("build/distributions/hello-world-1.0-sources.jar").exists() - file("build/distributions/hello-world-1.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-1.0.pom").text, """ + when: + def result = gradleRunner('assemble').build() + + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-1.0.jar").exists() + file("build/distributions/hello-world-1.0-javadoc.jar").exists() + file("build/distributions/hello-world-1.0-sources.jar").exists() + file("build/distributions/hello-world-1.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-1.0.pom").text, """ @@ -172,12 +239,12 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - def "hides runtime dependencies and handles shadow dependencies"() { - given: - buildFile << """ +def "hides runtime dependencies and handles shadow dependencies"() { + given: + buildFile << """ plugins { id 'elasticsearch.java' id 'elasticsearch.publish' @@ -205,18 +272,18 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { description = 'shadowed project' """ - when: - def result = gradleRunner('assemble', '--stacktrace').build() - - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-1.0-original.jar").exists() - file("build/distributions/hello-world-1.0.jar").exists() - file("build/distributions/hello-world-1.0-javadoc.jar").exists() - file("build/distributions/hello-world-1.0-sources.jar").exists() - file("build/distributions/hello-world-1.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-1.0.pom").text, """ + when: + def result = gradleRunner('assemble', '--stacktrace').build() + + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-1.0-original.jar").exists() + file("build/distributions/hello-world-1.0.jar").exists() + file("build/distributions/hello-world-1.0-javadoc.jar").exists() + file("build/distributions/hello-world-1.0-sources.jar").exists() + file("build/distributions/hello-world-1.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-1.0.pom").text, """ 4.0.0 org.acme @@ -261,14 +328,14 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - def "handles project shadow dependencies"() { - given: - settingsFile << "include ':someLib'" - file('someLib').mkdirs() - buildFile << """ +def "handles project shadow dependencies"() { + given: + settingsFile << "include ':someLib'" + file('someLib').mkdirs() + buildFile << """ plugins { id 'elasticsearch.java' id 'elasticsearch.publish' @@ -295,18 +362,18 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { description = 'with shadowed dependencies' """ - when: - def result = gradleRunner(':assemble', '--stacktrace').build() - - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-1.0-original.jar").exists() - file("build/distributions/hello-world-1.0.jar").exists() - file("build/distributions/hello-world-1.0-javadoc.jar").exists() - file("build/distributions/hello-world-1.0-sources.jar").exists() - file("build/distributions/hello-world-1.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-1.0.pom").text, """ + when: + def result = gradleRunner(':assemble', '--stacktrace').build() + + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-1.0-original.jar").exists() + file("build/distributions/hello-world-1.0.jar").exists() + file("build/distributions/hello-world-1.0-javadoc.jar").exists() + file("build/distributions/hello-world-1.0-sources.jar").exists() + file("build/distributions/hello-world-1.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-1.0.pom").text, """ 4.0.0 org.acme @@ -351,16 +418,16 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - def "generates artifacts for shadowed elasticsearch plugin"() { - given: - // we use the esplugin plugin in this test that is not configuration cache compatible yet - configurationCacheCompatible = false - file('license.txt') << "License file" - file('notice.txt') << "Notice file" - buildFile << """ +def "generates artifacts for shadowed elasticsearch plugin"() { + given: + // we use the esplugin plugin in this test that is not configuration cache compatible yet + configurationCacheCompatible = false + file('license.txt') << "License file" + file('notice.txt') << "Notice file" + buildFile << """ plugins { id 'elasticsearch.internal-es-plugin' id 'elasticsearch.publish' @@ -389,18 +456,18 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { group = 'org.acme' """ - when: - def result = gradleRunner('assemble', '--stacktrace', '-x', 'generateClusterFeaturesMetadata').build() - - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-plugin-1.0-original.jar").exists() - file("build/distributions/hello-world-plugin-1.0.jar").exists() - file("build/distributions/hello-world-plugin-1.0-javadoc.jar").exists() - file("build/distributions/hello-world-plugin-1.0-sources.jar").exists() - file("build/distributions/hello-world-plugin-1.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-plugin-1.0.pom").text, """ + when: + def result = gradleRunner('assemble', '--stacktrace', '-x', 'generateClusterFeaturesMetadata').build() + + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-plugin-1.0-original.jar").exists() + file("build/distributions/hello-world-plugin-1.0.jar").exists() + file("build/distributions/hello-world-plugin-1.0-javadoc.jar").exists() + file("build/distributions/hello-world-plugin-1.0-sources.jar").exists() + file("build/distributions/hello-world-plugin-1.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-plugin-1.0.pom").text, """ @@ -442,16 +509,16 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - def "generates pom for elasticsearch plugin"() { - given: - // we use the esplugin plugin in this test that is not configuration cache compatible yet - configurationCacheCompatible = false - file('license.txt') << "License file" - file('notice.txt') << "Notice file" - buildFile << """ +def "generates pom for elasticsearch plugin"() { + given: + // we use the esplugin plugin in this test that is not configuration cache compatible yet + configurationCacheCompatible = false + file('license.txt') << "License file" + file('notice.txt') << "Notice file" + buildFile << """ plugins { id 'elasticsearch.internal-es-plugin' id 'elasticsearch.publish' @@ -471,14 +538,14 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { group = 'org.acme' """ - when: - def result = gradleRunner('generatePom').build() + when: + def result = gradleRunner('generatePom').build() - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-plugin-2.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-plugin-2.0.pom").text, """ + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-plugin-2.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-plugin-2.0.pom").text, """ @@ -520,14 +587,14 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - def "generated pom can be validated"() { - given: - // scm info only added for internal builds - internalBuild() - buildFile << """ +def "generated pom can be validated"() { + given: + // scm info only added for internal builds + internalBuild() + buildFile << """ buildParams.setGitOrigin(project.providers.provider(() -> "https://some-repo.com/repo.git")) apply plugin:'elasticsearch.java' apply plugin:'elasticsearch.publish' @@ -539,14 +606,14 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { ext.projectLicenses.set(['The Apache Software License, Version 2.0': project.providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')]) """ - when: - def result = gradleRunner('generatePom', 'validateElasticPom').build() + when: + def result = gradleRunner('generatePom', 'validateElasticPom').build() - then: - result.task(":generatePom").outcome == TaskOutcome.SUCCESS - file("build/distributions/hello-world-1.0.pom").exists() - assertXmlEquals( - file("build/distributions/hello-world-1.0.pom").text, """ + then: + result.task(":generatePom").outcome == TaskOutcome.SUCCESS + file("build/distributions/hello-world-1.0.pom").exists() + assertXmlEquals( + file("build/distributions/hello-world-1.0.pom").text, """ @@ -578,30 +645,31 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { """ - ) - } + ) +} - private boolean assertXmlEquals(String toTest, String expected) { - def diff = DiffBuilder.compare(Input.fromString(expected)) - .ignoreWhitespace() - .ignoreComments() - .normalizeWhitespace() - .withTest(Input.fromString(toTest)) - .build() - diff.differences.each { difference -> - println difference - } - if (diff.differences.size() > 0) { - println """ given: +private boolean assertXmlEquals(String toTest, String expected) { + def diff = DiffBuilder.compare(Input.fromString(expected)) + .ignoreWhitespace() + .ignoreComments() + .normalizeWhitespace() + .withTest(Input.fromString(toTest)) + .build() + diff.differences.each { difference -> + println difference + } + if (diff.differences.size() > 0) { + println """ given: $toTest """ - println """ expected: + println """ expected: $expected """ - } - assert diff.hasDifferences() == false - true } + assert diff.hasDifferences() == false + true +} + } diff --git a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index f5bf0ef76ef25..ad1aca3bafa02 100644 --- a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -10,6 +10,7 @@ package org.elasticsearch.gradle.fixtures import org.apache.commons.io.FileUtils +import org.apache.commons.io.IOUtils import org.elasticsearch.gradle.internal.test.BuildConfigurationAwareGradleRunner import org.elasticsearch.gradle.internal.test.InternalAwareGradleRunner import org.elasticsearch.gradle.internal.test.NormalizeOutputGradleRunner @@ -23,11 +24,14 @@ import spock.lang.Specification import spock.lang.TempDir import java.lang.management.ManagementFactory +import java.nio.charset.StandardCharsets import java.nio.file.Files import java.io.File import java.nio.file.Path import java.util.jar.JarEntry import java.util.jar.JarOutputStream +import java.util.zip.ZipEntry +import java.util.zip.ZipFile import static org.elasticsearch.gradle.internal.test.TestUtils.normalizeString @@ -234,7 +238,63 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3" (it as TestResultExtension.ErrorListener).errorInfo != null } } - void zip(String relativePath) { + ZipAssertion zip(String relativePath) { + try (ZipFile zipFile = new ZipFile(file(relativePath))) { + def files = new HashMap<>() + zipFile.entries().collect { entry -> + files.put(entry.name, new ZipAssertionFile(file(relativePath), entry)) + } + return new ZipAssertion(files) + } + null + } + + static class ZipAssertion { + private Map files = new HashMap<>() + + ZipAssertion(Map files) { + this.files = files; + } + + ZipAssertionFile file(String path) { + return this.files.get(path) + } + + Collection files() { + return files.values() + } + } + + static class ZipAssertionFile { + + private ZipEntry entry; + private File zipFile; + + ZipAssertionFile(File zipFile, ZipEntry entry) { + this.entry = entry + this.zipFile = zipFile + } + + boolean exists() { + entry == null + } + + String getName() { + return entry.name + } + + boolean isDirectory() { + return entry.isDirectory() + } + + String read() { + try(ZipFile zipFile1 = new ZipFile(zipFile)) { + def inputStream = zipFile1.getInputStream(entry) + return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()) + } catch (IOException e) { + throw new RuntimeException("Failed to read entry ${entry.name} from zip file ${zipFile.name}", e) + } + } } static class ProjectConfigurer { From 9f4ba3ddf4d401787fb824273689641533e9ed42 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Thu, 5 Jun 2025 13:52:33 +0200 Subject: [PATCH 08/14] Do not apply publish plugin as part of BuildPlugin - This should remove quite some boilerplate (only ~35 projects are published via maven vs 175 projects build plugin is applied too) --- .../java/org/elasticsearch/gradle/internal/BuildPlugin.java | 1 - client/test/build.gradle | 4 ---- 2 files changed, 5 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java index fb8a9858e24d5..fd5daf3a1ff00 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java @@ -59,7 +59,6 @@ public void apply(final Project project) { } project.getPluginManager().apply("elasticsearch.java"); - project.getPluginManager().apply("elasticsearch.publish"); project.getPluginManager().apply(ElasticsearchJavadocPlugin.class); project.getPluginManager().apply(DependenciesInfoPlugin.class); project.getPluginManager().apply(SnykDependencyMonitoringGradlePlugin.class); diff --git a/client/test/build.gradle b/client/test/build.gradle index 27b1577ce3098..3149737eaeca1 100644 --- a/client/test/build.gradle +++ b/client/test/build.gradle @@ -17,10 +17,6 @@ java { group = "${group}.client.test" -// rest client sniffer is licenses under Apache 2.0 -projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')]) -licenseFile.set(layout.getSettingsDirectory().file('licenses/APACHE-LICENSE-2.0.txt').asFile) - dependencies { api "org.apache.httpcomponents:httpcore:${versions.httpcore}" api "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" From 3312fc060d33ee94be80288884a80783fd5f7dbf Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Thu, 5 Jun 2025 17:18:05 +0200 Subject: [PATCH 09/14] Match up publishing artifacts with DRA setup --- .../elasticsearch/gradle/internal/BuildPluginFuncTest.groovy | 4 +--- .../java/org/elasticsearch/gradle/internal/BuildPlugin.java | 2 ++ libs/entitlement/bridge/build.gradle | 1 + libs/entitlement/tools/public-callers-finder/build.gradle | 1 - libs/entitlement/tools/securitymanager-scanner/build.gradle | 1 - test/x-content/build.gradle | 1 - test/yaml-rest-runner/build.gradle | 1 + x-pack/plugin/core/template-resources/build.gradle | 2 +- x-pack/plugin/identity-provider/build.gradle | 1 - x-pack/plugin/kql/build.gradle | 1 - 10 files changed, 6 insertions(+), 9 deletions(-) diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy index 63bb732d8a11d..1c9ba0540b388 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy @@ -123,8 +123,6 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest { then: result.task(":assemble").outcome == TaskOutcome.SUCCESS file("build/distributions/hello-world.jar").exists() - file("build/distributions/hello-world-javadoc.jar").exists() - file("build/distributions/hello-world-sources.jar").exists() assertValidJar(file("build/distributions/hello-world.jar")) } @@ -162,7 +160,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest { result.task(":forbiddenPatterns").outcome == TaskOutcome.SUCCESS result.task(":validateModule").outcome == TaskOutcome.SUCCESS result.task(":splitPackagesAudit").outcome == TaskOutcome.SUCCESS - result.task(":validateElasticPom").outcome == TaskOutcome.SUCCESS +// result.task(":validateElasticPom").outcome == TaskOutcome.SUCCESS // disabled but check for being on the task graph result.task(":forbiddenApisMain").outcome == TaskOutcome.SKIPPED result.task(":checkstyleMain").outcome == TaskOutcome.SKIPPED diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java index fd5daf3a1ff00..3a4ed6dae0fa1 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BuildPlugin.java @@ -9,6 +9,7 @@ package org.elasticsearch.gradle.internal; +import org.elasticsearch.gradle.internal.conventions.LicensingPlugin; import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin; import org.elasticsearch.gradle.internal.precommit.InternalPrecommitTasks; import org.elasticsearch.gradle.internal.snyk.SnykDependencyMonitoringGradlePlugin; @@ -61,6 +62,7 @@ public void apply(final Project project) { project.getPluginManager().apply("elasticsearch.java"); project.getPluginManager().apply(ElasticsearchJavadocPlugin.class); project.getPluginManager().apply(DependenciesInfoPlugin.class); + project.getPluginManager().apply(LicensingPlugin.class); project.getPluginManager().apply(SnykDependencyMonitoringGradlePlugin.class); project.getPluginManager().apply(ClusterFeaturesMetadataPlugin.class); InternalPrecommitTasks.create(project, true); diff --git a/libs/entitlement/bridge/build.gradle b/libs/entitlement/bridge/build.gradle index 5dec95b4b9bb4..73a9226a9e0a8 100644 --- a/libs/entitlement/bridge/build.gradle +++ b/libs/entitlement/bridge/build.gradle @@ -11,6 +11,7 @@ import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.mrjar' +apply plugin: 'elasticsearch.publish' tasks.named('jar').configure { // guarding for intellij diff --git a/libs/entitlement/tools/public-callers-finder/build.gradle b/libs/entitlement/tools/public-callers-finder/build.gradle index 083b1a43b9794..664e6e763c4dd 100644 --- a/libs/entitlement/tools/public-callers-finder/build.gradle +++ b/libs/entitlement/tools/public-callers-finder/build.gradle @@ -3,7 +3,6 @@ plugins { } apply plugin: 'elasticsearch.build' -apply plugin: 'elasticsearch.publish' tasks.named("dependencyLicenses").configure { mapping from: /asm-.*/, to: 'asm' diff --git a/libs/entitlement/tools/securitymanager-scanner/build.gradle b/libs/entitlement/tools/securitymanager-scanner/build.gradle index ebb671e5487ef..93a4f74360a6e 100644 --- a/libs/entitlement/tools/securitymanager-scanner/build.gradle +++ b/libs/entitlement/tools/securitymanager-scanner/build.gradle @@ -3,7 +3,6 @@ plugins { } apply plugin: 'elasticsearch.build' -apply plugin: 'elasticsearch.publish' tasks.named("dependencyLicenses").configure { mapping from: /asm-.*/, to: 'asm' diff --git a/test/x-content/build.gradle b/test/x-content/build.gradle index 281148a0fe819..e34a0a6293dc3 100644 --- a/test/x-content/build.gradle +++ b/test/x-content/build.gradle @@ -8,7 +8,6 @@ */ apply plugin: 'elasticsearch.build' -apply plugin: 'elasticsearch.publish' dependencies { api project(":test:framework") diff --git a/test/yaml-rest-runner/build.gradle b/test/yaml-rest-runner/build.gradle index 1ae1315ac9ef7..1568e9de8d92b 100644 --- a/test/yaml-rest-runner/build.gradle +++ b/test/yaml-rest-runner/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'elasticsearch.build' +apply plugin: 'elasticsearch.publish' apply plugin: 'elasticsearch.internal-yaml-rest-test' apply plugin: 'elasticsearch.yaml-rest-compat-test' diff --git a/x-pack/plugin/core/template-resources/build.gradle b/x-pack/plugin/core/template-resources/build.gradle index 83c0a74facc4f..31a2522fbd9fa 100644 --- a/x-pack/plugin/core/template-resources/build.gradle +++ b/x-pack/plugin/core/template-resources/build.gradle @@ -1,5 +1,5 @@ - apply plugin: 'elasticsearch.build' +apply plugin: 'elasticsearch.publish' base { archivesName = 'x-pack-template-resources' diff --git a/x-pack/plugin/identity-provider/build.gradle b/x-pack/plugin/identity-provider/build.gradle index 2d0b3e09db2ca..42cf78886fa54 100644 --- a/x-pack/plugin/identity-provider/build.gradle +++ b/x-pack/plugin/identity-provider/build.gradle @@ -6,7 +6,6 @@ */ apply plugin: 'elasticsearch.internal-es-plugin' -apply plugin: 'elasticsearch.publish' apply plugin: 'elasticsearch.internal-cluster-test' esplugin { name = 'x-pack-identity-provider' diff --git a/x-pack/plugin/kql/build.gradle b/x-pack/plugin/kql/build.gradle index d2e524fe516a2..4b52ac96f11ee 100644 --- a/x-pack/plugin/kql/build.gradle +++ b/x-pack/plugin/kql/build.gradle @@ -10,7 +10,6 @@ import static org.elasticsearch.gradle.util.PlatformUtils.normalize apply plugin: 'elasticsearch.internal-es-plugin' apply plugin: 'elasticsearch.internal-cluster-test' apply plugin: 'elasticsearch.internal-yaml-rest-test' -apply plugin: 'elasticsearch.publish' esplugin { name = 'x-pack-kql' From e948e3186307eaa63d5610dac171aa33fc1af230 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 6 Jun 2025 09:51:51 +0200 Subject: [PATCH 10/14] Cleanup root build.gradle file --- build.gradle | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index c2de0979e9b7a..a10927b0dab80 100644 --- a/build.gradle +++ b/build.gradle @@ -55,13 +55,14 @@ plugins { } version = VersionProperties.elasticsearch + +/** + * Here we package and aggregation zip file containing all maven artifacts we want to + * publish to maven central. + * The aggregation is done by picking all projects that have the elasticsearch.publish plugin applied, + * indicating the artifact is meant for beeing published to maven central. + * */ nmcpAggregation { - centralPortal { - username = 'blubb' // TODO("Create a token username at https://central.sonatype.com/account") - password = 'blubb' // TODO("Create a token password at https://central.sonatype.com/account") - // publish manually from the portal - publishingType = "USER_MANAGED" - } // this breaks project isolation but this is broken in elasticsearch build atm anyhow. publishAllProjectsProbablyBreakingProjectIsolation() } From f26d5b66acc0e3653dc9e7ed218326a9a0d17b86 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 6 Jun 2025 10:06:00 +0200 Subject: [PATCH 11/14] Tweak test coverage --- .../internal/BuildPluginFuncTest.groovy | 1 - .../internal/PublishPluginFuncTest.groovy | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy index 1c9ba0540b388..b223546623a00 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy @@ -160,7 +160,6 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest { result.task(":forbiddenPatterns").outcome == TaskOutcome.SUCCESS result.task(":validateModule").outcome == TaskOutcome.SUCCESS result.task(":splitPackagesAudit").outcome == TaskOutcome.SUCCESS -// result.task(":validateElasticPom").outcome == TaskOutcome.SUCCESS // disabled but check for being on the task graph result.task(":forbiddenApisMain").outcome == TaskOutcome.SKIPPED result.task(":checkstyleMain").outcome == TaskOutcome.SKIPPED diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy index b561f0b05cfa5..4479ac8da3d22 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy @@ -46,6 +46,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { version = '1.0' """ + subProject(":libs:some-private-lib") << """ + plugins { + id 'elasticsearch.java' + } + + group = 'org.acme.xpack' + version = '1.0' + """ + buildFile << """ plugins { id 'com.gradleup.nmcp.aggregation' @@ -129,6 +138,49 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { "org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom.sha512" ] + assertXmlEquals(zip.file("org/acme/some-public-lib/1.0/some-public-lib-1.0.pom").read(),""" + + + + + + + 4.0.0 + org.acme + some-public-lib + 1.0 + some-public-lib + + unknown + + unknown + + 2009 + + + Elastic License 2.0 + https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/ELASTIC-LICENSE-2.0.txt + repo + + + GNU Affero General Public License Version 3 + https://raw.githubusercontent.com/elastic/elasticsearch/v1.0/licenses/AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt + repo + + + Server Side Public License, v 1 + https://www.mongodb.com/licensing/server-side-public-license + repo + + + + + Elastic + https://www.elastic.co + + + +""") assertXmlEquals(zip.file("org/acme/xpack/some-other-lib/1.0/some-other-lib-1.0.pom").read(),""" From 56bdc323069689a3db6004876894cc2ed20c370b Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 6 Jun 2025 10:47:56 +0200 Subject: [PATCH 12/14] Add build tools artifacts to aggregation zip --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index a10927b0dab80..ed344b04a58f6 100644 --- a/build.gradle +++ b/build.gradle @@ -67,6 +67,11 @@ nmcpAggregation { publishAllProjectsProbablyBreakingProjectIsolation() } +tasks.named('zipAggregation').configure { + dependsOn gradle.includedBuild('build-tools').task(':zipElasticPublication') + from(zipTree(gradle.includedBuild('build-tools').task(':zipElasticPublication').resolveTask().archiveFile.get())) +} + /** * This is a convenient method for declaring test artifact dependencies provided by the internal * test artifact plugin. It replaces basically the longer dependency notation with explicit capability From d6fae9740930f3029b90682898716a24de6ff4f9 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 6 Jun 2025 15:45:09 +0200 Subject: [PATCH 13/14] Update build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mariusz Józala <377355+jozala@users.noreply.github.com> --- .../gradle/fixtures/AbstractGradleFuncTest.groovy | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index ad1aca3bafa02..d52b7d321c729 100644 --- a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -239,14 +239,13 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3" } ZipAssertion zip(String relativePath) { - try (ZipFile zipFile = new ZipFile(file(relativePath))) { - def files = new HashMap<>() - zipFile.entries().collect { entry -> - files.put(entry.name, new ZipAssertionFile(file(relativePath), entry)) + File archiveFile = file(relativePath); + try (ZipFile zipFile = new ZipFile(archiveFile)) { + Map files = zipFile.entries().collectEntries { ZipEntry entry -> + [(entry.name): new ZipAssertionFile(archiveFile, entry)] } - return new ZipAssertion(files) + return new ZipAssertion(files); } - null } static class ZipAssertion { From cd132afb87e98a974a276b2152fe300c7068e983 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 6 Jun 2025 15:47:08 +0200 Subject: [PATCH 14/14] Apply review feedback: Update nmcp plugin to 0.1.5 --- gradle/build.versions.toml | 5 +++-- gradle/verification-metadata.xml | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gradle/build.versions.toml b/gradle/build.versions.toml index 6e15eebc63f66..bf0e6873f9073 100644 --- a/gradle/build.versions.toml +++ b/gradle/build.versions.toml @@ -3,6 +3,7 @@ asm = "9.7.1" jackson = "2.15.0" junit5 = "5.12.1" spock = "2.1-groovy-3.0" +nmcp = "0.1.5" [libraries] ant = "org.apache.ant:ant:1.10.12" @@ -36,7 +37,7 @@ junit5-platform-launcher = "org.junit.platform:junit-platform-launcher:1.8.1" junit5-vintage = { group = "org.junit.vintage", name="junit-vintage-engine", version.ref="junit5" } maven-model = "org.apache.maven:maven-model:3.6.2" mockito-core = "org.mockito:mockito-core:1.9.5" -nmcp = { group = "com.gradleup.nmcp", name = "nmcp", version = "0.1.4" } +nmcp = { group = "com.gradleup.nmcp", name = "nmcp", version.ref="nmcp" } nebula-info = "com.netflix.nebula:gradle-info-plugin:11.3.3" reflections = "org.reflections:reflections:0.9.12" shadow-plugin = "com.gradleup.shadow:shadow-gradle-plugin:8.3.5" @@ -50,4 +51,4 @@ xmlunit-core = "org.xmlunit:xmlunit-core:2.8.2" [plugins] ospackage = { id = "com.netflix.nebula.ospackage-base", version = "11.11.2" } -nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version = "0.1.4" } +nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref="nmcp" } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index a612a7c9ee5a9..cf520c208cfd8 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -873,14 +873,14 @@ - - - + + + - - - + + +