[7.17] [Build] Add support for publishing to maven central (#128659) (#129487)

This is the 7.17 backport of #128659 #129209
This commit is contained in:
Rene Groeschke 2025-06-16 17:34:10 +02:00 committed by GitHub
parent b3cfe8feb2
commit f5f3f2ce9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 113 additions and 14 deletions

View file

@ -52,6 +52,7 @@ echo --- Building release artifacts
$BUILD_SNAPSHOT_ARG \
buildReleaseArtifacts \
exportCompressedDockerImages \
zipAggregation \
:distribution:generateDependenciesReport
PATH="$PATH:${JAVA_HOME}/bin" # Required by the following script

View file

@ -24,8 +24,8 @@ plugins {
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 {
@ -73,7 +73,9 @@ dependencies {
api buildLibs.maven.model
api buildLibs.shadow.plugin
api buildLibs.apache.rat
compileOnly buildLibs.checkstyle
api buildLibs.nmcp
compileOnly buildLibs.checkstyle
api(buildLibs.spotless.plugin) {
exclude module: "groovy-xml"
}

View file

@ -13,6 +13,8 @@ import groovy.util.Node;
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.BasePluginExtension;
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.ProviderFactory;
import org.gradle.api.publish.PublishingExtension;
@ -64,6 +67,7 @@ public class PublishPlugin implements Plugin<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);
@ -81,6 +85,11 @@ public class PublishPlugin implements Plugin<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<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
publication.getPom().withXml(xml -> {

View file

@ -24,7 +24,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@ -32,7 +32,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@ -51,11 +51,11 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
id 'java'
id 'elasticsearch.global-build-info'
}
apply plugin:'elasticsearch.build'
group = 'org.acme'
description = "some example project"
repositories {
maven {
name = "local-test"
@ -66,7 +66,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
}
mavenCentral()
}
dependencies {
jarHell 'org.elasticsearch:elasticsearch-core:current'
}
@ -82,7 +82,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
* Side Public License, v 1.
*/
package org.elasticsearch;
public class SampleClass {
}
""".stripIndent()
@ -114,8 +114,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"))
}
@ -138,7 +136,7 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
}
licenseFile.set(file("LICENSE"))
noticeFile.set(file("NOTICE"))
tasks.named("forbiddenApisMain").configure {enabled = false }
tasks.named('checkstyleMain').configure { enabled = false }
tasks.named('loggerUsageCheck').configure { enabled = false }
@ -151,7 +149,6 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
result.task(":licenseHeaders").outcome == TaskOutcome.SUCCESS
result.task(":forbiddenPatterns").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

View file

@ -8,6 +8,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;
@ -57,7 +58,7 @@ public class BuildPlugin implements Plugin<Project> {
}
project.getPluginManager().apply("elasticsearch.java");
project.getPluginManager().apply("elasticsearch.publish");
project.getPluginManager().apply(LicensingPlugin.class);
project.getPluginManager().apply(ElasticsearchJavadocPlugin.class);
project.getPluginManager().apply(DependenciesInfoPlugin.class);
project.getPluginManager().apply(SnykDependencyMonitoringGradlePlugin.class);

View file

@ -14,9 +14,13 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.attributes.Category;
import org.gradle.api.attributes.Usage;
import org.gradle.api.plugins.JavaPlugin;
public class DependenciesInfoPlugin implements Plugin<Project> {
public static String USAGE_ATTRIBUTE = "DependenciesInfo";
@Override
public void apply(final Project project) {
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
@ -42,6 +46,9 @@ public class DependenciesInfoPlugin implements Plugin<Project> {
)
);
dependenciesInfoFilesConfiguration.attributes(
attributes -> attributes.attribute(Usage.USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, USAGE_ATTRIBUTE))
);
project.getArtifacts().add("dependenciesInfoFiles", depsInfo);
}

View file

@ -57,6 +57,7 @@ plugins {
id 'elasticsearch.release-tools'
id 'elasticsearch.auto-backporting'
id 'elasticsearch.versions'
id 'com.gradleup.nmcp.aggregation'
}
/**
@ -94,6 +95,22 @@ def filterIntermediatePatches = { List<Version> versions ->
versions.groupBy {"${it.major}.${it.minor}"}.values().collect {it.max()}
}
nmcpAggregation {
// this breaks project isolation but this is broken in elasticsearch build atm anyhow.
publishAllProjectsProbablyBreakingProjectIsolation()
}
tasks.named('zipAggregation').configure {
// put this in a place that works well with our DRA infrastructure
archiveFileName.unset();
archiveBaseName.set("elasticsearch-maven-aggregation")
archiveVersion.set(VersionProperties.elasticsearch)
destinationDirectory.set(layout.buildDirectory.dir("distributions"));
dependsOn gradle.includedBuild('build-tools').task(':zipElasticPublication')
from(zipTree(gradle.includedBuild('build-tools').task(':zipElasticPublication').resolveTask().archiveFile.get()))
}
tasks.register("updateCIBwcVersions") {
def writeVersions = { File file, List<Version> versions ->
file.text = ""

View file

@ -28,6 +28,9 @@ configurations {
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.DOCUMENTATION))
}
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, DependenciesInfoPlugin.USAGE_ATTRIBUTE))
}
}
}

View file

@ -3,6 +3,7 @@ asm = "9.3"
jackson = "2.10.4"
junit5 = "5.8.1"
spock = "2.1-groovy-3.0"
nmcp = "0.1.5"
[libraries]
ant = "org.apache.ant:ant:1.10.12"
@ -32,6 +33,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"

View file

@ -984,6 +984,16 @@
<sha256 value="989cfe6b6a47b530971add6d55c043ecc1eded4144a66a981be5770ffee3de1c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.gradleup.gratatouille" name="gratatouille-runtime" version="0.0.8">
<artifact name="gratatouille-runtime-0.0.8.jar">
<sha256 value="03eefe964f5d06b2263a28724e3d3503c0670ea1846c208afa918d86d4d08472" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.gradleup.nmcp" name="nmcp" version="0.1.5">
<artifact name="nmcp-0.1.5.jar">
<sha256 value="9c823adc282e96b206956e4a63cb1552bb2bbcec6010bbb6aa9c3d18ecd3f915" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.gradleup.shadow" name="shadow-gradle-plugin" version="8.3.5">
<artifact name="shadow-gradle-plugin-8.3.5.jar">
<sha256 value="54e08dd20a82775e3317a4725a1a5e4ec8b1b1c0f346de702a49d9ed4815b735" origin="Generated by Gradle"/>
@ -1169,6 +1179,11 @@
<sha256 value="88ac9fd1bb51f82bcc664cc1eb9c225c90dc4389d660231b4cc737bebfe7d0aa" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp3" name="logging-interceptor" version="4.12.0">
<artifact name="logging-interceptor-4.12.0.jar">
<sha256 value="f3e8d5f0903c250c2b55d2f47fcfe008e80634385da8385161c7a63aaed0c74c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp3" name="okhttp" version="4.12.0">
<artifact name="okhttp-4.12.0.jar">
<sha256 value="b1050081b14bb7a3a7e55a4d3ef01b5dcfabc453b4573a4fc019767191d5f4e0" origin="Generated by Gradle"/>
@ -1189,6 +1204,11 @@
<sha256 value="67543f0736fc422ae927ed0e504b98bc5e269fda0d3500579337cb713da28412" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio-jvm" version="3.8.0">
<artifact name="okio-jvm-3.8.0.jar">
<sha256 value="88fb79f6fe1a462acf0a3bd2576ba1525c29f29825efeceec70a747ac1c6fc90" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.sun.activation" name="jakarta.activation" version="1.2.1">
<artifact name="jakarta.activation-1.2.1.jar">
<sha256 value="d84d4ba8b55cdb7fdcbb885e6939386367433f56f5ab8cfdc302a7c3587fa92b" origin="Generated by Gradle"/>
@ -4031,6 +4051,11 @@
<sha256 value="55e989c512b80907799f854309f3bc7782c5b3d13932442d0379d5c472711504" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib" version="2.1.20">
<artifact name="kotlin-stdlib-2.1.20.jar">
<sha256 value="1bcc74e8ce84e2c25eaafde10f1248349cce3062b6e36978cbeec610db1e930a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-common" version="1.5.10">
<artifact name="kotlin-stdlib-common-1.5.10.jar">
<sha256 value="d958ce94beda85f865829fb95012804866db7d5246615fd71a2f5aabca3e7994" origin="Generated by Gradle"/>
@ -4056,6 +4081,16 @@
<sha256 value="75ed5680aaacfd94b93c3695d8eb8bfa7cf83893d2e46ca9788345c52d393f8a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk7" version="1.8.0">
<artifact name="kotlin-stdlib-jdk7-1.8.0.jar">
<sha256 value="4c889d1d9803f5f2eb6c1592a6b7e62369ac7660c9eee15aba16fec059163666" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk7" version="1.8.21">
<artifact name="kotlin-stdlib-jdk7-1.8.21.jar">
<sha256 value="33d148db0e11debd0d90677d28242bced907f9c77730000fd597867089039d86" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk7" version="1.9.10">
<artifact name="kotlin-stdlib-jdk7-1.9.10.jar">
<sha256 value="ac6361bf9ad1ed382c2103d9712c47cdec166232b4903ed596e8876b0681c9b7" origin="Generated by Gradle"/>
@ -4066,11 +4101,36 @@
<sha256 value="270b05aa3cc92f157a7ed71ff09cf136ee3fb18cbac94f71a12931009c49f550" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk8" version="1.8.0">
<artifact name="kotlin-stdlib-jdk8-1.8.0.jar">
<sha256 value="05b62804441b0c9a1920b6b7d5cf7329a4e24b6258478e32b1f046ca01900946" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk8" version="1.8.21">
<artifact name="kotlin-stdlib-jdk8-1.8.21.jar">
<sha256 value="3db752a30074f06ee6c57984aa6f27da44f4d2bbc7f5442651f6988f1cb2b7d7" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk8" version="1.9.10">
<artifact name="kotlin-stdlib-jdk8-1.9.10.jar">
<sha256 value="a4c74d94d64ce1abe53760fe0389dd941f6fc558d0dab35e47c085a11ec80f28" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-test" version="2.0.0">
<artifact name="kotlin-test-2.0.0.jar">
<sha256 value="8438cc11769da31cbb4445dfafd12c08cf4015daa387963106f121a85a56864c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-serialization-core-jvm" version="1.8.1">
<artifact name="kotlinx-serialization-core-jvm-1.8.1.jar">
<sha256 value="3565b6d4d789bf70683c45566944287fc1d8dc75c23d98bd87d01059cc76f2b3" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-serialization-json-jvm" version="1.8.1">
<artifact name="kotlinx-serialization-json-jvm-1.8.1.jar">
<sha256 value="8769e5647557e3700919c32d508f5c5dad53c5d8234cd10846354fbcff14aa24" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jline" name="jline" version="3.9.0">
<artifact name="jline-3.9.0.jar">
<sha256 value="d2b986fd15d05e0b900faba776c1de9b4dc4a4fcdfeaa12a8ab8fb2b290ed527" origin="Generated by Gradle"/>