-
Notifications
You must be signed in to change notification settings - Fork 991
[Build] Support publishing maven artifacts directly to maven central #2397
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
6511849
9372ba1
c7b6364
dcb5552
c187d6f
3937161
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 |
---|---|---|
|
@@ -567,6 +567,7 @@ class BuildPlugin implements Plugin<Project> { | |
|
||
private void configureMaven(Project project) { | ||
project.getPluginManager().apply("maven-publish") | ||
project.getPluginManager().apply("com.gradleup.nmcp") | ||
|
||
// Configure Maven publication | ||
project.publishing { | ||
|
@@ -587,13 +588,6 @@ class BuildPlugin implements Plugin<Project> { | |
// Configure Maven Pom | ||
configurePom(project, project.publishing.publications.main) | ||
|
||
// Disable the publishing tasks since we only need the pom generation tasks. | ||
// If we are working with a project that has a scala variant (see below), we need to modify the pom's | ||
// artifact id which the publish task does not like (it fails validation when run). | ||
project.getTasks().withType(PublishToMavenRepository) { PublishToMavenRepository m -> | ||
m.enabled = false | ||
} | ||
|
||
// Configure Scala Variants if present | ||
project.getPlugins().withType(SparkVariantPlugin).whenPluginAdded { | ||
// Publishing gets weird when you introduce variants into the project. | ||
|
@@ -608,7 +602,8 @@ class BuildPlugin implements Plugin<Project> { | |
|
||
// Main variant needs the least configuration on its own, since it is the default publication created above. | ||
sparkVariants.defaultVariant { SparkVariant variant -> | ||
updateVariantPomLocationAndArtifactId(project, project.publishing.publications.main, variant) | ||
project.publishing.publications.main.setAlias(true) | ||
updateVariantArtifactId(project, project.publishing.publications.main, variant) | ||
} | ||
|
||
// For each spark variant added, we need to do a few things: | ||
|
@@ -659,7 +654,7 @@ class BuildPlugin implements Plugin<Project> { | |
suppressAllPomMetadataWarnings() // We get it. Gradle metadata is better than Maven Poms | ||
} | ||
configurePom(project, variantPublication) | ||
updateVariantPomLocationAndArtifactId(project, variantPublication, variant) | ||
updateVariantArtifactId(project, variantPublication, variant) | ||
} | ||
} | ||
} | ||
|
@@ -672,14 +667,6 @@ class BuildPlugin implements Plugin<Project> { | |
} | ||
|
||
private static void configurePom(Project project, MavenPublication publication) { | ||
// Set the pom's destination to the distribution directory | ||
project.tasks.withType(GenerateMavenPom).all { GenerateMavenPom pom -> | ||
if (pom.name == "generatePomFileFor${publication.name.capitalize()}Publication") { | ||
BasePluginExtension baseExtension = project.getExtensions().getByType(BasePluginExtension.class); | ||
pom.destination = project.provider({"${project.buildDir}/distributions/${baseExtension.archivesName.get()}-${project.getVersion()}.pom"}) | ||
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. this results in a deprecation warning and we would not want to rely on that workaround anymore. |
||
} | ||
} | ||
|
||
// add all items necessary for publication | ||
Provider<String> descriptionProvider = project.provider({ project.getDescription() }) | ||
MavenPom pom = publication.getPom() | ||
|
@@ -722,7 +709,8 @@ class BuildPlugin implements Plugin<Project> { | |
while (dependenciesIterator.hasNext()) { | ||
Node dependencyNode = dependenciesIterator.next() | ||
String artifact = dependencyNode.get("artifactId").text() | ||
if (artifact == dependency.getName()) { | ||
// handle scala variants by splitting via "_" and checking the first part | ||
if (artifact =~ dependency.getName().split('_')[0]) { | ||
dependenciesIterator.remove() | ||
break | ||
} | ||
|
@@ -732,23 +720,11 @@ class BuildPlugin implements Plugin<Project> { | |
} | ||
} | ||
|
||
private static void updateVariantPomLocationAndArtifactId(Project project, MavenPublication publication, SparkVariant variant) { | ||
private static void updateVariantArtifactId(Project project, MavenPublication publication, SparkVariant variant) { | ||
// Add variant classifier to the pom file name if required | ||
String classifier = variant.shouldClassifySparkVersion() && variant.isDefaultVariant() == false ? "-${variant.getName()}" : '' | ||
BasePluginExtension baseExtension = project.getExtensions().getByType(BasePluginExtension.class); | ||
String filename = "${baseExtension.archivesName.get()}_${variant.scalaMajorVersion}-${project.getVersion()}${classifier}" | ||
// Fix the pom name | ||
project.tasks.withType(GenerateMavenPom).all { GenerateMavenPom pom -> | ||
if (pom.name == "generatePomFileFor${publication.name.capitalize()}Publication") { | ||
pom.destination = project.provider({"${project.buildDir}/distributions/${filename}.pom"}) | ||
} | ||
} | ||
// Fix the artifactId. Note: The publishing task does not like this happening. Hence it is disabled. | ||
publication.getPom().withXml { XmlProvider xml -> | ||
Node root = xml.asNode() | ||
Node artifactId = (root.get('artifactId') as NodeList).get(0) as Node | ||
artifactId.setValue("${baseExtension.archivesName.get()}_${variant.scalaMajorVersion}") | ||
} | ||
// Fix the artifact id | ||
publication.setArtifactId("${baseExtension.archivesName.get()}_${variant.scalaMajorVersion}") | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import jdk.internal.foreign.abi.Binding | ||
import org.elasticsearch.hadoop.gradle.buildtools.ConcatFilesTask | ||
import org.elasticsearch.hadoop.gradle.buildtools.DependenciesInfoTask | ||
import org.elasticsearch.hadoop.gradle.buildtools.DependencyLicensesTask | ||
|
@@ -132,26 +133,6 @@ javadoc { | |
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
main { | ||
getPom().withXml { XmlProvider xml -> | ||
Node root = xml.asNode() | ||
|
||
// add clojars repo to pom | ||
Node repositories = root.appendNode('repositories') | ||
Node repository = repositories.appendNode('repository') | ||
repository.appendNode('id', 'clojars.org') | ||
repository.appendNode('url', 'https://clojars.org/repo') | ||
BasePluginExtension baseExtension = project.getExtensions().getByType(BasePluginExtension.class) | ||
|
||
// Correct the artifact Id, otherwise it is listed as 'dist' | ||
root.get('artifactId').get(0).setValue(baseExtension.archivesName.get()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Name of the directory under the root of the zip file that will contain the zip contents | ||
String zipContentDir = "elasticsearch-hadoop-${project.version}" | ||
|
||
|
@@ -179,8 +160,28 @@ task('distZip', type: Zip) { | |
|
||
distribution { | ||
dependsOn(distZip) | ||
|
||
} | ||
|
||
|
||
publishing { | ||
publications { | ||
main { | ||
artifact tasks.named('distZip') | ||
getPom().withXml { XmlProvider xml -> | ||
Node root = xml.asNode() | ||
|
||
// add clojars repo to pom | ||
Node repositories = root.appendNode('repositories') | ||
Node repository = repositories.appendNode('repository') | ||
repository.appendNode('id', 'clojars.org') | ||
repository.appendNode('url', 'https://clojars.org/repo') | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
// Add a task in the root project that collects all the dependencyReport data for each project | ||
// Concatenates the dependencies CSV files into a single file | ||
task generateDependenciesReport(type: ConcatFilesTask) { concatDepsTask -> | ||
|
@@ -197,3 +198,15 @@ task generateDependenciesReport(type: ConcatFilesTask) { concatDepsTask -> | |
project.tasks.named('dependencyLicenses', DependencyLicensesTask) { | ||
it.dependencies = project.configurations.licenseChecks | ||
} | ||
|
||
|
||
tasks.register('copyPoms', Copy) { | ||
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. temporally we want to keep the build compatible with the existing DRA build. We can remove this workaround once we rely our releases on the new mechanism |
||
BasePluginExtension baseExtension = project.getExtensions().getByType(BasePluginExtension.class); | ||
from(tasks.named('generatePomFileForMainPublication')) | ||
into(new File(project.buildDir, 'distributions')) | ||
rename 'pom-default.xml', "${baseExtension.archivesName.get()}-${project.getVersion()}.pom" | ||
} | ||
|
||
tasks.named('distribution').configure { | ||
dependsOn 'copyPoms' | ||
} |
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.
we explicitly list the artifacts we want to publish here to avoid any accidental publication