Skip to content

Commit 5425db6

Browse files
authored
[8.18] [Build] Add support for publishing to maven central (elastic#128659) (elastic#129080)
* [Build] Add support for publishing to maven central (elastic#128659) This ensures we package an aggregation zip with all artifacts we want to publish to maven central as part of a release. Running zipAggregation will produce a zip file in the build/nmcp/zip folder. The content of this zip is meant to match the maven artifacts we have currently declared as dra maven artifacts. (cherry picked from commit 3420831) # Conflicts: # build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy # build.gradle # libs/entitlement/tools/public-callers-finder/build.gradle * Fix publish plugin func test
1 parent 7ccf54d commit 5425db6

File tree

17 files changed

+530
-190
lines changed

17 files changed

+530
-190
lines changed

build-conventions/build.gradle

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,88 +17,89 @@ buildscript {
1717
}
1818

1919
plugins {
20-
id 'java-gradle-plugin'
21-
id 'java-test-fixtures'
22-
id 'eclipse'
20+
id 'java-gradle-plugin'
21+
id 'java-test-fixtures'
22+
id 'eclipse'
2323
}
2424

2525
group = "org.elasticsearch"
2626

2727
// This project contains Checkstyle rule implementations used by IDEs which use a Java 11 runtime
2828
java {
29-
targetCompatibility = 11
30-
sourceCompatibility = 11
29+
targetCompatibility = 17
30+
sourceCompatibility = 17
3131
}
3232

3333
gradlePlugin {
34-
// We already configure publication and we don't need or want the one that comes
35-
// with the java-gradle-plugin
36-
automatedPublishing = false
37-
plugins {
38-
internalLicenseheaders {
39-
id = 'elasticsearch.internal-licenseheaders'
40-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin'
41-
}
42-
eclipse {
43-
id = 'elasticsearch.eclipse'
44-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.EclipseConventionPlugin'
45-
}
46-
publish {
47-
id = 'elasticsearch.publish'
48-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.PublishPlugin'
49-
}
50-
licensing {
51-
id = 'elasticsearch.licensing'
52-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.LicensingPlugin'
53-
}
54-
buildTools {
55-
id = 'elasticsearch.build-tools'
56-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.BuildToolsConventionsPlugin'
57-
}
58-
versions {
59-
id = 'elasticsearch.versions'
60-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.VersionPropertiesPlugin'
61-
}
62-
formatting {
63-
id = 'elasticsearch.formatting'
64-
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.FormattingPrecommitPlugin'
65-
}
34+
// We already configure publication and we don't need or want the one that comes
35+
// with the java-gradle-plugin
36+
automatedPublishing = false
37+
plugins {
38+
internalLicenseheaders {
39+
id = 'elasticsearch.internal-licenseheaders'
40+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin'
6641
}
42+
eclipse {
43+
id = 'elasticsearch.eclipse'
44+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.EclipseConventionPlugin'
45+
}
46+
publish {
47+
id = 'elasticsearch.publish'
48+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.PublishPlugin'
49+
}
50+
licensing {
51+
id = 'elasticsearch.licensing'
52+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.LicensingPlugin'
53+
}
54+
buildTools {
55+
id = 'elasticsearch.build-tools'
56+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.BuildToolsConventionsPlugin'
57+
}
58+
versions {
59+
id = 'elasticsearch.versions'
60+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.VersionPropertiesPlugin'
61+
}
62+
formatting {
63+
id = 'elasticsearch.formatting'
64+
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.FormattingPrecommitPlugin'
65+
}
66+
}
6767
}
6868

6969
repositories {
70-
mavenCentral()
71-
gradlePluginPortal()
70+
mavenCentral()
71+
gradlePluginPortal()
7272
}
7373

7474
dependencies {
75-
api buildLibs.maven.model
76-
api buildLibs.shadow.plugin
77-
api buildLibs.apache.rat
78-
compileOnly buildLibs.checkstyle
79-
constraints {
80-
api("org.eclipse.platform:org.eclipse.osgi:3.18.300") {
81-
because("Use the same version as we do in spotless gradle plugin at runtime")
82-
}
83-
}
84-
api(buildLibs.spotless.plugin) {
85-
exclude module: "groovy-xml"
75+
api buildLibs.maven.model
76+
api buildLibs.shadow.plugin
77+
api buildLibs.apache.rat
78+
api buildLibs.nmcp
79+
compileOnly buildLibs.checkstyle
80+
constraints {
81+
api("org.eclipse.platform:org.eclipse.osgi:3.18.300") {
82+
because("Use the same version as we do in spotless gradle plugin at runtime")
8683
}
84+
}
85+
api(buildLibs.spotless.plugin) {
86+
exclude module: "groovy-xml"
87+
}
8788
}
8889

8990
project.getPlugins().withType(JavaBasePlugin.class) {
90-
java.getModularity().getInferModulePath().set(false);
91-
eclipse.getClasspath().getFile().whenMerged { classpath ->
92-
/*
93-
* give each source folder a unique corresponding output folder
94-
* outside of the usual `build` folder. We can't put the build
95-
* in the usual build folder because eclipse becomes *very* sad
96-
* if we delete it. Which `gradlew clean` does all the time.
97-
*/
98-
classpath.getEntries().findAll{ s -> s instanceof SourceFolder }.eachWithIndex { s, i ->
99-
s.setOutput("out/eclipse" + i)
100-
}
91+
java.getModularity().getInferModulePath().set(false);
92+
eclipse.getClasspath().getFile().whenMerged { classpath ->
93+
/*
94+
* give each source folder a unique corresponding output folder
95+
* outside of the usual `build` folder. We can't put the build
96+
* in the usual build folder because eclipse becomes *very* sad
97+
* if we delete it. Which `gradlew clean` does all the time.
98+
*/
99+
classpath.getEntries().findAll { s -> s instanceof SourceFolder }.eachWithIndex { s, i ->
100+
s.setOutput("out/eclipse" + i)
101101
}
102+
}
102103
}
103104

104105
tasks.withType(JavaCompile).configureEach {

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension;
1515
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin;
1616

17+
import nmcp.NmcpPlugin;
18+
1719
import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
1820
import org.elasticsearch.gradle.internal.conventions.precommit.PomValidationPrecommitPlugin;
1921
import org.elasticsearch.gradle.internal.conventions.util.Util;
@@ -27,6 +29,7 @@
2729
import org.gradle.api.plugins.ExtensionContainer;
2830
import org.gradle.api.plugins.JavaLibraryPlugin;
2931
import org.gradle.api.plugins.JavaPlugin;
32+
import org.gradle.api.plugins.JavaPluginExtension;
3033
import org.gradle.api.provider.MapProperty;
3134
import org.gradle.api.provider.Provider;
3235
import org.gradle.api.provider.ProviderFactory;
@@ -65,6 +68,7 @@ public void apply(Project project) {
6568
project.getPluginManager().apply(MavenPublishPlugin.class);
6669
project.getPluginManager().apply(PomValidationPrecommitPlugin.class);
6770
project.getPluginManager().apply(LicensingPlugin.class);
71+
project.getPluginManager().apply(NmcpPlugin.class);
6872
configureJavadocJar(project);
6973
configureSourcesJar(project);
7074
configurePomGeneration(project);
@@ -82,6 +86,11 @@ private void configurePublications(Project project) {
8286
publication.from(project.getComponents().getByName("java"));
8387
}
8488
});
89+
project.getPlugins().withType(JavaPlugin.class, plugin -> {
90+
var javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
91+
javaPluginExtension.withJavadocJar();
92+
javaPluginExtension.withSourcesJar();
93+
});
8594
@SuppressWarnings("unchecked")
8695
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
8796
publication.getPom().withXml(xml -> {

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
123123
then:
124124
result.task(":assemble").outcome == TaskOutcome.SUCCESS
125125
file("build/distributions/hello-world.jar").exists()
126-
file("build/distributions/hello-world-javadoc.jar").exists()
127-
file("build/distributions/hello-world-sources.jar").exists()
128126
assertValidJar(file("build/distributions/hello-world.jar"))
129127
}
130128

@@ -162,7 +160,6 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {
162160
result.task(":forbiddenPatterns").outcome == TaskOutcome.SUCCESS
163161
result.task(":validateModule").outcome == TaskOutcome.SUCCESS
164162
result.task(":splitPackagesAudit").outcome == TaskOutcome.SUCCESS
165-
result.task(":validateElasticPom").outcome == TaskOutcome.SUCCESS
166163
// disabled but check for being on the task graph
167164
result.task(":forbiddenApisMain").outcome == TaskOutcome.SKIPPED
168165
result.task(":checkstyleMain").outcome == TaskOutcome.SKIPPED

0 commit comments

Comments
 (0)