Build: Remove old maven deploy support (#20403)

* Build: Remove old maven deploy support

This change removes the old maven deploy that we have in parallel to
maven-publish, and makes maven-publish fully work with publishing to
maven local. Using `gradle publishToMavenLocal` should be used to
publish to .m2.

Note that there is an unfortunate hack that means for
zip artifacts we must first create/publish a dummy pom file, and then
follow that with the real pom file. It would be nice to have the pom
file contains packaging=zip, but maven central then requires sources and
javadocs. But our zips are really just attached artifacts, so we already
set the packaging type to pom for our zip files. This change just works
around a limitation of the underlying maven publishing library which
silently skips attached artifacts when the packaging type is set to pom.

relates #20164
closes #20375

* Remove unnecessary extra spacing
This commit is contained in:
Ryan Ernst 2016-09-19 15:10:41 -07:00 committed by GitHub
parent e2854bb3a4
commit 85b8f29415
14 changed files with 49 additions and 120 deletions

View File

@ -17,7 +17,6 @@
* under the License.
*/
import com.bmuschko.gradle.nexus.NexusPlugin
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.plugins.ide.eclipse.model.SourceFolder
@ -52,68 +51,6 @@ subprojects {
}
}
}
plugins.withType(NexusPlugin).whenPluginAdded {
modifyPom {
project {
url 'https://github.com/elastic/elasticsearch'
inceptionYear '2009'
scm {
url 'https://github.com/elastic/elasticsearch'
connection 'scm:https://elastic@github.com/elastic/elasticsearch'
developerConnection 'scm:git://github.com/elastic/elasticsearch.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}
extraArchive {
javadoc = true
tests = false
}
nexus {
String buildSnapshot = System.getProperty('build.snapshot', 'true')
if (buildSnapshot == 'false') {
Repository repo = new RepositoryBuilder().findGitDir(project.rootDir).build()
String shortHash = repo.resolve('HEAD')?.name?.substring(0,7)
repositoryUrl = project.hasProperty('build.repository') ? project.property('build.repository') : "file://${System.getenv('HOME')}/elasticsearch-releases/${version}-${shortHash}/"
}
}
// we have our own username/password prompts so that they only happen once
// TODO: add gpg signing prompts, which is tricky, as the buildDeb/buildRpm tasks are executed before this code block
project.gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it.name == 'uploadArchives' }) {
Console console = System.console()
// no need for username/password on local deploy
if (project.nexus.repositoryUrl.startsWith('file://')) {
project.rootProject.allprojects.each {
it.ext.nexusUsername = 'foo'
it.ext.nexusPassword = 'bar'
}
} else {
if (project.hasProperty('nexusUsername') == false) {
String nexusUsername = console.readLine('\nNexus username: ')
project.rootProject.allprojects.each {
it.ext.nexusUsername = nexusUsername
}
}
if (project.hasProperty('nexusPassword') == false) {
String nexusPassword = new String(console.readPassword('\nNexus password: '))
project.rootProject.allprojects.each {
it.ext.nexusPassword = nexusPassword
}
}
}
}
}
}
}
allprojects {

View File

@ -95,7 +95,6 @@ dependencies {
compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r'
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
compile 'de.thetaphi:forbiddenapis:2.2'
compile 'com.bmuschko:gradle-nexus-plugin:2.3.1'
compile 'org.apache.rat:apache-rat:0.11'
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.0.1'
}

View File

@ -28,11 +28,10 @@ import org.gradle.api.Task
import org.gradle.api.XmlProvider
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.ModuleVersionIdentifier
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.maven.MavenPom
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
@ -63,7 +62,6 @@ class BuildPlugin implements Plugin<Project> {
project.pluginManager.apply('nebula.info-java')
project.pluginManager.apply('nebula.info-scm')
project.pluginManager.apply('nebula.info-jar')
project.pluginManager.apply('com.bmuschko.nexus')
project.pluginManager.apply(ProvidedBasePlugin)
globalBuildInfo(project)
@ -71,6 +69,8 @@ class BuildPlugin implements Plugin<Project> {
configureConfigurations(project)
project.ext.versions = VersionProperties.versions
configureCompile(project)
configureJavadocJar(project)
configureSourcesJar(project)
configurePomGeneration(project)
configureTest(project)
@ -267,11 +267,6 @@ class BuildPlugin implements Plugin<Project> {
project.configurations.compile.dependencies.all(disableTransitiveDeps)
project.configurations.testCompile.dependencies.all(disableTransitiveDeps)
project.configurations.provided.dependencies.all(disableTransitiveDeps)
// add exclusions to the pom directly, for each of the transitive deps of this project's deps
project.modifyPom { MavenPom pom ->
pom.withXml(fixupDependencies(project))
}
}
/** Adds repositores used by ES dependencies */
@ -411,6 +406,25 @@ class BuildPlugin implements Plugin<Project> {
}
}
/** Adds a javadocJar task to generate a jar containing javadocs. */
static void configureJavadocJar(Project project) {
Jar javadocJarTask = project.task('javadocJar', type: Jar)
javadocJarTask.classifier = 'javadoc'
javadocJarTask.group = 'build'
javadocJarTask.description = 'Assembles a jar containing javadocs.'
javadocJarTask.from(project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME))
project.assemble.dependsOn(javadocJarTask)
}
static void configureSourcesJar(Project project) {
Jar sourcesJarTask = project.task('sourcesJar', type: Jar)
sourcesJarTask.classifier = 'sources'
sourcesJarTask.group = 'build'
sourcesJarTask.description = 'Assembles a jar containing source files.'
sourcesJarTask.from(project.sourceSets.main.allSource)
project.assemble.dependsOn(sourcesJarTask)
}
/** Adds additional manifest info to jars, and adds source and javadoc jars */
static void configureJars(Project project) {
project.tasks.withType(Jar) { Jar jarTask ->

View File

@ -56,12 +56,8 @@ public class PluginBuildPlugin extends BuildPlugin {
// 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
project.signArchives.enabled = false
addClientJarPomGeneration(project)
addClientJarTask(project)
if (isModule == false) {
addZipPomGeneration(project)
}
} else {
// no client plugin, so use the pom file from nebula, without jar, for the zip
project.ext.set("nebulaPublish.maven.jar", false)
@ -152,17 +148,12 @@ 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('generatePomFileForJarPublication', project.jar, project.javadocJar, project.sourcesJar)
clientJar.dependsOn(project.jar, 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 pomFileName = jarFile.fileName.toString().replace('.jar', '.pom')
String clientPomFileName = clientFileName.replace('.jar', '.pom')
Files.copy(jarFile.resolveSibling(pomFileName), 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),
@ -197,7 +188,7 @@ public class PluginBuildPlugin extends BuildPlugin {
project.publishing {
publications {
jar(MavenPublication) {
clientJar(MavenPublication) {
from project.components.java
artifactId = artifactId + '-client'
pom.withXml { XmlProvider xml ->
@ -221,7 +212,15 @@ public class PluginBuildPlugin extends BuildPlugin {
publications {
zip(MavenPublication) {
artifact project.bundlePlugin
pom.packaging = 'pom'
}
// HUGE HACK: the underlying maven publication library refuses to deploy any attached artifacts
// when the packaging type is set to 'pom'. So here we create another publication using the same
// name that has the "real" pom, and rely on the fact that gradle will execute the publish tasks
// in alphabetical order. We cannot setup a dependency between the tasks because the publishing
// tasks are created *extremely* late in the configuration phase, so that we cannot get ahold
// of the actual task. Furthermore, this entire hack only exists so we can make publishing to
// maven local work, since we publish to maven central externally.
zipReal(MavenPublication) {
pom.withXml { XmlProvider xml ->
Node root = xml.asNode()
root.appendNode('name', project.pluginProperties.extension.name)

View File

@ -64,7 +64,3 @@ dependencies {
// No licenses for our benchmark deps (we don't ship benchmarks)
dependencyLicenses.enabled = false
extraArchive {
javadoc = false
}

View File

@ -20,7 +20,6 @@
group = 'org.elasticsearch.plugin'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'com.bmuschko.nexus'
esplugin {
name 'client-benchmark-noop-api'

View File

@ -26,9 +26,6 @@ apply plugin: 'ru.vyarus.animalsniffer'
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_7
install.enabled = false
uploadArchives.enabled = false
dependencies {
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
@ -61,4 +58,4 @@ namingConventions.enabled = false
//we aren't releasing this jar
thirdPartyAudit.enabled = false
test.enabled = false
test.enabled = false

View File

@ -22,7 +22,6 @@ import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import org.elasticsearch.gradle.BuildPlugin
apply plugin: 'elasticsearch.build'
apply plugin: 'com.bmuschko.nexus'
apply plugin: 'nebula.optional-base'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'

View File

@ -132,13 +132,6 @@ subprojects {
// note: the group must be correct before applying the nexus plugin, or it will capture the wrong value...
project.group = "org.elasticsearch.distribution.${project.name}"
project.archivesBaseName = 'elasticsearch'
apply plugin: 'com.bmuschko.nexus'
// we must create our own install task, because it is only added when the java plugin is added
task install(type: Upload, description: "Installs the 'archives' artifacts into the local Maven repository.", group: 'Upload') {
configuration = configurations.archives
MavenRepositoryHandlerConvention repositoriesHandler = (MavenRepositoryHandlerConvention)getRepositories().getConvention().getPlugin(MavenRepositoryHandlerConvention)
repositoriesHandler.mavenInstaller()
}
// TODO: the map needs to be an input of the tasks, so that when it changes, the task will re-run...
/*****************************************************************************
@ -191,16 +184,11 @@ subprojects {
/*****************************************************************************
* Publishing setup *
*****************************************************************************/
BuildPlugin.configurePomGeneration(project)
apply plugin: 'nebula.info-scm'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
publishing {
publications {
nebula {
artifactId 'elasticsearch'
}
}
if (['zip', 'integ-test-zip'].contains(it.name)) {
BuildPlugin.configurePomGeneration(project)
apply plugin: 'nebula.info-scm'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
}
}

View File

@ -30,8 +30,13 @@ artifacts {
publishing {
publications {
nebula {
artifactId 'elasticsearch'
artifact buildZip
}
nebulaRealPom(MavenPublication) {
artifactId 'elasticsearch'
pom.packaging = 'pom'
}
}
}

View File

@ -28,9 +28,5 @@ task buildTar(type: Tar) {
artifacts {
'default' buildTar
project.afterEvaluate {
// gradle is broken for extensions that contain a dot, so we must be explicit about the name of the .asc file
project.signArchives.singleSignature.type = 'tar.gz.asc'
}
}

View File

@ -30,8 +30,13 @@ artifacts {
publishing {
publications {
nebula {
artifactId 'elasticsearch'
artifact buildZip
}
nebulaRealPom(MavenPublication) {
artifactId 'elasticsearch'
pom.packaging = 'pom'
}
}
}

View File

@ -35,8 +35,4 @@ subprojects {
if (project.file('src/main/config').exists()) {
throw new InvalidModelException("Modules cannot contain config files")
}
// these are implementation details of our build, no need to publish them!
install.enabled = false
uploadArchives.enabled = false
}

View File

@ -22,7 +22,6 @@ configure(subprojects.findAll { it.parent.path == project.path }) {
group = 'org.elasticsearch.plugin'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'com.bmuschko.nexus'
esplugin {
// for local ES plugins, the name of the plugin is the same as the directory