-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[Build] Add support for publishing to maven central #128659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c87f6dd
959b5fb
20982c3
09edc9d
7a7b570
49f0c47
970792c
9f4ba3d
3312fc0
e948e31
f26d5b6
56bdc32
d6fae97
cd132af
6d2d072
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nmcp plugin does not support java 11, so we can bump |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. required by the PublishPlugin |
||
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 -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated: we might want to remove all the leftover eclipse related configuration to our build. we do not support that anymore. |
||
/* | ||
* 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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure we include sources and javadoc jars as maven artifacts |
||
var javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); | ||
javaPluginExtension.withJavadocJar(); | ||
javaPluginExtension.withSourcesJar(); | ||
}); | ||
@SuppressWarnings("unchecked") | ||
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses"); | ||
publication.getPom().withXml(xml -> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
Comment on lines
-126
to
-127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these files no longer produced? I couldn't pinpoint the change which disable that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its related to removing the publish plugin from the build plugin. see #128659 (comment) And there's now better PublishPlugin test coverage for this in PublishPluginFunc |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applying some default formatting here that doesn't change logic