-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Only configure publishing if it's applied externally #32351
Changes from all commits
4d061a2
1f25694
49d9bf6
01af981
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 |
---|---|---|
|
@@ -19,23 +19,19 @@ | |
package org.elasticsearch.gradle.plugin | ||
|
||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin | ||
import nebula.plugin.info.scm.ScmInfoPlugin | ||
import nebula.plugin.publishing.maven.MavenScmPlugin | ||
import org.elasticsearch.gradle.BuildPlugin | ||
import org.elasticsearch.gradle.NoticeTask | ||
import org.elasticsearch.gradle.test.RestIntegTestTask | ||
import org.elasticsearch.gradle.test.RunTask | ||
import org.gradle.api.InvalidUserDataException | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.XmlProvider | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin | ||
import org.gradle.api.publish.maven.tasks.GenerateMavenPom | ||
import org.gradle.api.tasks.SourceSet | ||
import org.gradle.api.tasks.bundling.Zip | ||
import org.gradle.jvm.tasks.Jar | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.StandardCopyOption | ||
import java.util.regex.Matcher | ||
import java.util.regex.Pattern | ||
/** | ||
|
@@ -55,16 +51,10 @@ public class PluginBuildPlugin extends BuildPlugin { | |
String name = project.pluginProperties.extension.name | ||
project.archivesBaseName = name | ||
|
||
if (project.pluginProperties.extension.hasClientJar) { | ||
// for plugins which work with the transport client, we copy the jar | ||
// file to a new name, copy the nebula generated pom to the same name, | ||
// and generate a different pom for the zip | ||
addClientJarPomGeneration(project) | ||
addClientJarTask(project) | ||
} | ||
// while the jar isn't normally published, we still at least build a pom of deps | ||
// in case it is published, for instance when other plugins extend this plugin | ||
configureJarPom(project) | ||
// set teh project description so it will be picked up by publishing | ||
project.description = project.pluginProperties.extension.description | ||
|
||
configurePublishing(project) | ||
|
||
project.integTestCluster.dependsOn(project.bundlePlugin) | ||
project.tasks.run.dependsOn(project.bundlePlugin) | ||
|
@@ -94,6 +84,32 @@ public class PluginBuildPlugin extends BuildPlugin { | |
project.tasks.create('run', RunTask) // allow running ES with this plugin in the foreground of a build | ||
} | ||
|
||
private void configurePublishing(Project project) { | ||
// Only configure publishing if applied externally | ||
if (project.pluginProperties.extension.hasClientJar) { | ||
project.plugins.apply(MavenScmPlugin.class) | ||
// Only change Jar tasks, we don't want a -client zip so we can't change archivesBaseName | ||
project.tasks.withType(Jar) { | ||
baseName = baseName + "-client" | ||
} | ||
// always configure publishing for client jars | ||
project.plugins.apply(MavenScmPlugin.class) | ||
project.publishing.publications.nebula(MavenPublication).artifactId( | ||
project.pluginProperties.extension.name + "-client" | ||
) | ||
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom generatePOMTask -> | ||
generatePOMTask.ext.pomFileName = "${project.archivesBaseName}-client-${project.version}.pom" | ||
} | ||
} else { | ||
project.plugins.withType(MavenPublishPlugin).whenPluginAdded { | ||
project.publishing.publications.nebula(MavenPublication).artifactId( | ||
project.pluginProperties.extension.name | ||
) | ||
} | ||
|
||
} | ||
} | ||
|
||
private static void configureDependencies(Project project) { | ||
project.dependencies { | ||
compileOnly "org.elasticsearch:elasticsearch:${project.versions.elasticsearch}" | ||
|
@@ -161,33 +177,6 @@ public class PluginBuildPlugin extends BuildPlugin { | |
} | ||
|
||
/** Adds a task to move jar and associated files to a "-client" name. */ | ||
protected static void addClientJarTask(Project project) { | ||
Task clientJar = project.tasks.create('clientJar') | ||
clientJar.dependsOn(project.jar, project.tasks.generatePomFileForClientJarPublication, project.javadocJar, project.sourcesJar) | ||
clientJar.doFirst { | ||
Path jarFile = project.jar.outputs.files.singleFile.toPath() | ||
String clientFileName = jarFile.fileName.toString().replace(project.version, "client-${project.version}") | ||
Files.copy(jarFile, jarFile.resolveSibling(clientFileName), StandardCopyOption.REPLACE_EXISTING) | ||
|
||
String clientPomFileName = clientFileName.replace('.jar', '.pom') | ||
Files.copy( | ||
project.tasks.generatePomFileForClientJarPublication.outputs.files.singleFile.toPath(), | ||
jarFile.resolveSibling(clientPomFileName), | ||
StandardCopyOption.REPLACE_EXISTING | ||
) | ||
|
||
String sourcesFileName = jarFile.fileName.toString().replace('.jar', '-sources.jar') | ||
String clientSourcesFileName = clientFileName.replace('.jar', '-sources.jar') | ||
Files.copy(jarFile.resolveSibling(sourcesFileName), jarFile.resolveSibling(clientSourcesFileName), | ||
StandardCopyOption.REPLACE_EXISTING) | ||
|
||
String javadocFileName = jarFile.fileName.toString().replace('.jar', '-javadoc.jar') | ||
String clientJavadocFileName = clientFileName.replace('.jar', '-javadoc.jar') | ||
Files.copy(jarFile.resolveSibling(javadocFileName), jarFile.resolveSibling(clientJavadocFileName), | ||
StandardCopyOption.REPLACE_EXISTING) | ||
} | ||
project.assemble.dependsOn(clientJar) | ||
} | ||
|
||
static final Pattern GIT_PATTERN = Pattern.compile(/git@([^:]+):([^\.]+)\.git/) | ||
|
||
|
@@ -209,39 +198,11 @@ public class PluginBuildPlugin extends BuildPlugin { | |
|
||
/** Adds nebula publishing task to generate a pom file for the plugin. */ | ||
protected static void addClientJarPomGeneration(Project project) { | ||
project.plugins.apply(MavenPublishPlugin.class) | ||
|
||
project.publishing { | ||
publications { | ||
clientJar(MavenPublication) { | ||
from project.components.java | ||
artifactId = project.pluginProperties.extension.name + '-client' | ||
pom.withXml { XmlProvider xml -> | ||
Node root = xml.asNode() | ||
root.appendNode('name', project.pluginProperties.extension.name) | ||
root.appendNode('description', project.pluginProperties.extension.description) | ||
root.appendNode('url', urlFromOrigin(project.scminfo.origin)) | ||
Node scmNode = root.appendNode('scm') | ||
scmNode.appendNode('url', project.scminfo.origin) | ||
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. Are you sure this isn't needed anymore? IIRC I added it because the scm info didn't get into the pom correctly at the time, and caused validation to fail when publishing to maven central. 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. I do remember doing diffs of before and after XMLs and didn't notice anything odd. Any edge cases or additional tests I should do ? 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. I just checked this again to make sure:
So the change produces no effect on the scm info in the 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. Have you run the build in a non git checkout? 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. I have not, but is that relevant for the poms we submit to maven or we just want to make sure it doesn't break ? 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. @rjernst This does work with non git and just produces:
This is consistent with master. |
||
} | ||
} | ||
} | ||
} | ||
project.plugins.apply(MavenScmPlugin.class) | ||
project.description = project.pluginProperties.extension.description | ||
} | ||
|
||
/** Configure the pom for the main jar of this plugin */ | ||
protected static void configureJarPom(Project project) { | ||
project.plugins.apply(ScmInfoPlugin.class) | ||
project.plugins.apply(MavenPublishPlugin.class) | ||
|
||
project.publishing { | ||
publications { | ||
nebula(MavenPublication) { | ||
artifactId project.pluginProperties.extension.name | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected void addNoticeGeneration(Project project) { | ||
File licenseFile = project.pluginProperties.extension.licenseFile | ||
|
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.
Is this method still used? It looks like the one use was removed above.