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-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..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; @@ -27,6 +29,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; @@ -65,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); @@ -82,6 +86,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/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..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 @@ -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,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 cc551057cd600..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 @@ -23,30 +23,233 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { configurationCacheCompatible = false } - def "artifacts and tweaked pom is published"() { + def "project with plugin applied is considered for maven central publication"() { given: - buildFile << """ + // required for JarHell to work + subProject(":libs:some-public-lib") << """ + plugins { + 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' + """ + + subProject(":libs:some-private-lib") << """ + plugins { + id 'elasticsearch.java' + } + + group = 'org.acme.xpack' + version = '1.0' + """ + + 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('assemble').build() + def result = gradleRunner(':zipAggregation').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, """ + result.task(":zipAggregation").outcome == TaskOutcome.SUCCESS + file("build/nmcp/zip/aggregation.zip").exists() + + + 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/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(),""" + + + + + + + 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' + } + + version = "1.0" + group = 'org.acme' + 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, """ @@ -88,12 +291,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' @@ -121,18 +324,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 @@ -177,14 +380,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' @@ -211,18 +414,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 @@ -267,16 +470,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' @@ -305,18 +508,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, """ @@ -358,16 +561,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' @@ -387,14 +590,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, """ @@ -436,14 +639,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' @@ -455,14 +658,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, """ @@ -494,30 +697,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-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..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; @@ -59,9 +60,9 @@ 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(LicensingPlugin.class); project.getPluginManager().apply(SnykDependencyMonitoringGradlePlugin.class); project.getPluginManager().apply(ClusterFeaturesMetadataPlugin.class); InternalPrecommitTasks.create(project, 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 72d8134869037..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 @@ -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,6 +238,64 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3" (it as TestResultExtension.ErrorListener).errorInfo != null } } + ZipAssertion zip(String relativePath) { + 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); + } + } + + 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 { private File projectDir diff --git a/build.gradle b/build.gradle index 7605eefc49b64..ed344b04a58f6 100644 --- a/build.gradle +++ b/build.gradle @@ -48,8 +48,28 @@ 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' +} + +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 { + // this breaks project isolation but this is broken in elasticsearch build atm anyhow. + publishAllProjectsProbablyBreakingProjectIsolation() +} + +tasks.named('zipAggregation').configure { + dependsOn gradle.includedBuild('build-tools').task(':zipElasticPublication') + from(zipTree(gradle.includedBuild('build-tools').task(':zipElasticPublication').resolveTask().archiveFile.get())) } /** @@ -295,7 +315,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 @@ -320,7 +340,7 @@ allprojects { } ext.withReleaseBuild = { Closure config -> - if(buildParams.snapshotBuild == false) { + if (buildParams.snapshotBuild == false) { config.call() } } 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}" diff --git a/gradle/build.versions.toml b/gradle/build.versions.toml index ae5dac9a29343..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,6 +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.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" @@ -49,3 +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.ref="nmcp" } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 566a640e9bd55..cf520c208cfd8 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/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'