diff --git a/build.gradle b/build.gradle index ad1f2456dea..459c8c8ae2e 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,26 @@ subprojects { group = 'org.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 { modifyPom { project { diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index e36451311e7..1b0d3c52127 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -69,6 +69,7 @@ dependencies { transitive = false } 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 '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.... diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index ab2ba5abfef..de5dbb73af6 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -33,6 +33,9 @@ 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.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.compile.JavaCompile import org.gradle.internal.jvm.Jvm @@ -54,7 +57,7 @@ class BuildPlugin implements Plugin { project.pluginManager.apply('java') project.pluginManager.apply('carrotsearch.randomized-testing') // 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-basic') project.pluginManager.apply('nebula.info-java') @@ -68,6 +71,7 @@ class BuildPlugin implements Plugin { configureConfigurations(project) project.ext.versions = VersionProperties.versions configureCompile(project) + configurePomGeneration(project) configureTest(project) configurePrecommit(project) @@ -266,44 +270,7 @@ class BuildPlugin implements Plugin { // add exclusions to the pom directly, for each of the transitive deps of this project's deps project.modifyPom { MavenPom pom -> - pom.withXml { 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 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) - } - } - } + pom.withXml(removeTransitiveDependencies(project)) } } @@ -332,6 +299,70 @@ class BuildPlugin implements Plugin { } } + /** 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 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 */ static void configureCompile(Project project) { project.ext.compactProfile = 'compact3' @@ -364,9 +395,12 @@ class BuildPlugin implements Plugin { } } - /** Adds additional manifest info to jars */ - static void configureJarManifest(Project project) { + /** Adds additional manifest info to jars, and adds source and javadoc jars */ + static void configureJars(Project project) { 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 { boolean isSnapshot = VersionProperties.elasticsearch.endsWith("-SNAPSHOT"); String version = VersionProperties.elasticsearch; diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index b04f959e068..36770ab35f7 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -18,11 +18,12 @@ */ 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.test.RestIntegTestTask import org.elasticsearch.gradle.test.RunTask import org.gradle.api.Project -import org.gradle.api.artifacts.Dependency import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.bundling.Zip @@ -50,6 +51,7 @@ public class PluginBuildPlugin extends BuildPlugin { } else { project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) + configurePomGeneration(project) } project.namingConventions { @@ -125,4 +127,32 @@ public class PluginBuildPlugin extends BuildPlugin { project.configurations.getByName('default').extendsFrom = [] 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) + } + } + } + } + } + } + + } } diff --git a/core/build.gradle b/core/build.gradle index ab3754e72ff..e12a80fcbf7 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -24,6 +24,18 @@ 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' +//apply plugin: 'nebula.source-jar' +//apply plugin: 'nebula.javadoc-jar' + +publishing { + publications { + nebula { + artifactId 'elasticsearch' + } + } +} archivesBaseName = 'elasticsearch' diff --git a/distribution/build.gradle b/distribution/build.gradle index 09050db2159..bb4cc167f10 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -158,6 +158,19 @@ subprojects { MavenFilteringHack.filter(it, expansions) } } + + /***************************************************************************** + * Publishing setup * + *****************************************************************************/ + apply plugin: 'nebula.maven-base-publish' + apply plugin: 'nebula.maven-scm' + publishing { + publications { + nebula { + artifactId 'elasticsearch' + } + } + } } /***************************************************************************** diff --git a/distribution/integ-test-zip/build.gradle b/distribution/integ-test-zip/build.gradle index 23191ff03a4..67f99aa884a 100644 --- a/distribution/integ-test-zip/build.gradle +++ b/distribution/integ-test-zip/build.gradle @@ -27,5 +27,13 @@ artifacts { archives buildZip } +publishing { + publications { + nebula { + artifact buildZip + } + } +} + integTest.dependsOn buildZip diff --git a/distribution/tar/build.gradle b/distribution/tar/build.gradle index 9edba6c11a2..72425659056 100644 --- a/distribution/tar/build.gradle +++ b/distribution/tar/build.gradle @@ -33,3 +33,4 @@ artifacts { project.signArchives.singleSignature.type = 'tar.gz.asc' } } + diff --git a/distribution/zip/build.gradle b/distribution/zip/build.gradle index 23191ff03a4..67f99aa884a 100644 --- a/distribution/zip/build.gradle +++ b/distribution/zip/build.gradle @@ -27,5 +27,13 @@ artifacts { archives buildZip } +publishing { + publications { + nebula { + artifact buildZip + } + } +} + integTest.dependsOn buildZip diff --git a/test/build.gradle b/test/build.gradle index 7feb332b717..a80ca59978c 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -25,6 +25,8 @@ subprojects { group = 'org.elasticsearch.test' 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