Build: Add pom generation to assemble task

In preparation for a unified release process, we need to be able to
generate the pom files independently of trying to actually publish. This
change adds back the maven-publish plugin just for that purpose. The
nexus plugin still exists for now, so that we do not break snapshots,
but that can be removed at a later time once snapshots are happenign
through the unified tools. Note I also changed the dir jars are written
into so that all our artifacts are under build/distributions.
This commit is contained in:
Ryan Ernst 2016-05-05 17:53:01 -07:00
parent 3912761572
commit e16af604bf
10 changed files with 171 additions and 42 deletions

View File

@ -28,6 +28,26 @@ subprojects {
group = 'org.elasticsearch' group = 'org.elasticsearch'
version = org.elasticsearch.gradle.VersionProperties.elasticsearch version = org.elasticsearch.gradle.VersionProperties.elasticsearch
// we only use maven publish to add tasks for pom generation
plugins.withType(MavenPublishPlugin).whenPluginAdded {
publishing {
publications {
// add license information to generated poms
all {
pom.withXml { XmlProvider xml ->
Node node = xml.asNode()
node.appendNode('inceptionYear', '2009')
Node license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', 'The Apache Software License, Version 2.0')
license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
license.appendNode('distribution', 'repo')
}
}
}
}
}
plugins.withType(NexusPlugin).whenPluginAdded { plugins.withType(NexusPlugin).whenPluginAdded {
modifyPom { modifyPom {
project { project {

View File

@ -69,6 +69,7 @@ dependencies {
transitive = false transitive = false
} }
compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3' compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
compile 'com.netflix.nebula:nebula-publishing-plugin:4.4.4'
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3' compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r' 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 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....

View File

@ -33,6 +33,9 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.maven.MavenPom import org.gradle.api.artifacts.maven.MavenPom
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.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.internal.jvm.Jvm import org.gradle.internal.jvm.Jvm
@ -54,7 +57,7 @@ class BuildPlugin implements Plugin<Project> {
project.pluginManager.apply('java') project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing') project.pluginManager.apply('carrotsearch.randomized-testing')
// these plugins add lots of info to our jars // these plugins add lots of info to our jars
configureJarManifest(project) // jar config must be added before info broker configureJars(project) // jar config must be added before info broker
project.pluginManager.apply('nebula.info-broker') project.pluginManager.apply('nebula.info-broker')
project.pluginManager.apply('nebula.info-basic') project.pluginManager.apply('nebula.info-basic')
project.pluginManager.apply('nebula.info-java') project.pluginManager.apply('nebula.info-java')
@ -68,6 +71,7 @@ class BuildPlugin implements Plugin<Project> {
configureConfigurations(project) configureConfigurations(project)
project.ext.versions = VersionProperties.versions project.ext.versions = VersionProperties.versions
configureCompile(project) configureCompile(project)
configurePomGeneration(project)
configureTest(project) configureTest(project)
configurePrecommit(project) configurePrecommit(project)
@ -266,44 +270,7 @@ class BuildPlugin implements Plugin<Project> {
// add exclusions to the pom directly, for each of the transitive deps of this project's deps // add exclusions to the pom directly, for each of the transitive deps of this project's deps
project.modifyPom { MavenPom pom -> project.modifyPom { MavenPom pom ->
pom.withXml { XmlProvider xml -> pom.withXml(removeTransitiveDependencies(project))
// first find if we have dependencies at all, and grab the node
NodeList depsNodes = xml.asNode().get('dependencies')
if (depsNodes.isEmpty()) {
return
}
// check each dependency for any transitive deps
for (Node depNode : depsNodes.get(0).children()) {
String groupId = depNode.get('groupId').get(0).text()
String artifactId = depNode.get('artifactId').get(0).text()
String version = depNode.get('version').get(0).text()
// collect the transitive deps now that we know what this dependency is
String depConfig = transitiveDepConfigName(groupId, artifactId, version)
Configuration configuration = project.configurations.findByName(depConfig)
if (configuration == null) {
continue // we did not make this dep non-transitive
}
Set<ResolvedArtifact> artifacts = configuration.resolvedConfiguration.resolvedArtifacts
if (artifacts.size() <= 1) {
// this dep has no transitive deps (or the only artifact is itself)
continue
}
// we now know we have something to exclude, so add the exclusion elements
Node exclusions = depNode.appendNode('exclusions')
for (ResolvedArtifact transitiveArtifact : artifacts) {
ModuleVersionIdentifier transitiveDep = transitiveArtifact.moduleVersion.id
if (transitiveDep.group == groupId && transitiveDep.name == artifactId) {
continue; // don't exclude the dependency itself!
}
Node exclusion = exclusions.appendNode('exclusion')
exclusion.appendNode('groupId', transitiveDep.group)
exclusion.appendNode('artifactId', transitiveDep.name)
}
}
}
} }
} }
@ -332,6 +299,70 @@ class BuildPlugin implements Plugin<Project> {
} }
} }
/** Returns a closure which can be used with a MavenPom for removing transitive dependencies. */
private static Closure removeTransitiveDependencies(Project project) {
// TODO: remove this when enforcing gradle 2.13+, it now properly handles exclusions
return { XmlProvider xml ->
// first find if we have dependencies at all, and grab the node
NodeList depsNodes = xml.asNode().get('dependencies')
if (depsNodes.isEmpty()) {
return
}
// check each dependency for any transitive deps
for (Node depNode : depsNodes.get(0).children()) {
String groupId = depNode.get('groupId').get(0).text()
String artifactId = depNode.get('artifactId').get(0).text()
String version = depNode.get('version').get(0).text()
// collect the transitive deps now that we know what this dependency is
String depConfig = transitiveDepConfigName(groupId, artifactId, version)
Configuration configuration = project.configurations.findByName(depConfig)
if (configuration == null) {
continue // we did not make this dep non-transitive
}
Set<ResolvedArtifact> artifacts = configuration.resolvedConfiguration.resolvedArtifacts
if (artifacts.size() <= 1) {
// this dep has no transitive deps (or the only artifact is itself)
continue
}
// we now know we have something to exclude, so add the exclusion elements
Node exclusions = depNode.appendNode('exclusions')
for (ResolvedArtifact transitiveArtifact : artifacts) {
ModuleVersionIdentifier transitiveDep = transitiveArtifact.moduleVersion.id
if (transitiveDep.group == groupId && transitiveDep.name == artifactId) {
continue; // don't exclude the dependency itself!
}
Node exclusion = exclusions.appendNode('exclusion')
exclusion.appendNode('groupId', transitiveDep.group)
exclusion.appendNode('artifactId', transitiveDep.name)
}
}
}
}
/**Configuration generation of maven poms. */
private static void configurePomGeneration(Project project) {
project.plugins.withType(MavenPublishPlugin.class).whenPluginAdded {
project.publishing {
publications {
all { MavenPublication publication -> // we only deal with maven
// add exclusions to the pom directly, for each of the transitive deps of this project's deps
publication.pom.withXml(removeTransitiveDependencies(project))
}
}
}
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t ->
// place the pom next to the jar it is for
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom")
// build poms with assemble
project.assemble.dependsOn(t)
}
}
}
/** Adds compiler settings to the project */ /** Adds compiler settings to the project */
static void configureCompile(Project project) { static void configureCompile(Project project) {
project.ext.compactProfile = 'compact3' project.ext.compactProfile = 'compact3'
@ -364,9 +395,12 @@ class BuildPlugin implements Plugin<Project> {
} }
} }
/** Adds additional manifest info to jars */ /** Adds additional manifest info to jars, and adds source and javadoc jars */
static void configureJarManifest(Project project) { static void configureJars(Project project) {
project.tasks.withType(Jar) { Jar jarTask -> project.tasks.withType(Jar) { Jar jarTask ->
// we put all our distributable files under distributions
jarTask.destinationDir = new File(project.buildDir, 'distributions')
// fixup the jar manifest
jarTask.doFirst { jarTask.doFirst {
boolean isSnapshot = VersionProperties.elasticsearch.endsWith("-SNAPSHOT"); boolean isSnapshot = VersionProperties.elasticsearch.endsWith("-SNAPSHOT");
String version = VersionProperties.elasticsearch; String version = VersionProperties.elasticsearch;

View File

@ -18,11 +18,12 @@
*/ */
package org.elasticsearch.gradle.plugin package org.elasticsearch.gradle.plugin
import nebula.plugin.publishing.maven.MavenManifestPlugin
import nebula.plugin.publishing.maven.MavenScmPlugin
import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.test.RestIntegTestTask import org.elasticsearch.gradle.test.RestIntegTestTask
import org.elasticsearch.gradle.test.RunTask import org.elasticsearch.gradle.test.RunTask
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.Zip import org.gradle.api.tasks.bundling.Zip
@ -50,6 +51,7 @@ public class PluginBuildPlugin extends BuildPlugin {
} else { } else {
project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
configurePomGeneration(project)
} }
project.namingConventions { project.namingConventions {
@ -125,4 +127,32 @@ public class PluginBuildPlugin extends BuildPlugin {
project.configurations.getByName('default').extendsFrom = [] project.configurations.getByName('default').extendsFrom = []
project.artifacts.add('default', bundle) project.artifacts.add('default', bundle)
} }
/**
* Adds the plugin jar and zip as publications.
*/
private static void configurePomGeneration(Project project) {
project.plugins.apply(MavenScmPlugin.class)
project.plugins.apply(MavenManifestPlugin.class)
project.publishing {
publications {
nebula {
artifact project.bundlePlugin
pom.withXml {
// overwrite the name/description in the pom nebula set up
Node root = asNode()
for (Node node : root.children()) {
if (node.name() == 'name') {
node.setValue(project.pluginProperties.extension.name)
} else if (node.name() == 'description') {
node.setValue(project.pluginProperties.extension.description)
}
}
}
}
}
}
}
} }

View File

@ -24,6 +24,18 @@ import org.elasticsearch.gradle.BuildPlugin
apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.build'
apply plugin: 'com.bmuschko.nexus' apply plugin: 'com.bmuschko.nexus'
apply plugin: 'nebula.optional-base' apply plugin: 'nebula.optional-base'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
//apply plugin: 'nebula.source-jar'
//apply plugin: 'nebula.javadoc-jar'
publishing {
publications {
nebula {
artifactId 'elasticsearch'
}
}
}
archivesBaseName = 'elasticsearch' archivesBaseName = 'elasticsearch'

View File

@ -158,6 +158,19 @@ subprojects {
MavenFilteringHack.filter(it, expansions) MavenFilteringHack.filter(it, expansions)
} }
} }
/*****************************************************************************
* Publishing setup *
*****************************************************************************/
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
publishing {
publications {
nebula {
artifactId 'elasticsearch'
}
}
}
} }
/***************************************************************************** /*****************************************************************************

View File

@ -27,5 +27,13 @@ artifacts {
archives buildZip archives buildZip
} }
publishing {
publications {
nebula {
artifact buildZip
}
}
}
integTest.dependsOn buildZip integTest.dependsOn buildZip

View File

@ -33,3 +33,4 @@ artifacts {
project.signArchives.singleSignature.type = 'tar.gz.asc' project.signArchives.singleSignature.type = 'tar.gz.asc'
} }
} }

View File

@ -27,5 +27,13 @@ artifacts {
archives buildZip archives buildZip
} }
publishing {
publications {
nebula {
artifact buildZip
}
}
}
integTest.dependsOn buildZip integTest.dependsOn buildZip

View File

@ -25,6 +25,8 @@ subprojects {
group = 'org.elasticsearch.test' group = 'org.elasticsearch.test'
apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.build'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
// the main files are actually test files, so use the appropriate forbidden api sigs // the main files are actually test files, so use the appropriate forbidden api sigs