Browse Source

Revert "Build: Switch to maven-publish plugin"

This reverts commit a90a2b34fc6fd135b23f6518156078f03804b7ae.
Ryan Ernst 9 years ago
parent
commit
f71f0d6010

+ 35 - 44
build.gradle

@@ -17,6 +17,7 @@
  * under the License.
  */
 
+import com.bmuschko.gradle.nexus.NexusPlugin
 import org.gradle.plugins.ide.eclipse.model.SourceFolder
 
 // common maven publishing configuration
@@ -24,55 +25,46 @@ subprojects {
   group = 'org.elasticsearch'
   version = org.elasticsearch.gradle.VersionProperties.elasticsearch
 
-  if (path.startsWith(':x-plugins')) {
-    // don't try to configure publshing for extra plugins attached to this build
-    return
-  }
+  plugins.withType(NexusPlugin).whenPluginAdded {
+    modifyPom {
+      project {
+        url 'https://github.com/elastic/elasticsearch'
+        inceptionYear '2009'
 
-  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')
+        scm {
+          url 'https://github.com/elastic/elasticsearch'
+          connection 'scm:https://elastic@github.com/elastic/elasticsearch'
+          developerConnection 'scm:git://github.com/elastic/elasticsearch.git'
+        }
 
-            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')
+        licenses {
+          license {
+            name 'The Apache Software License, Version 2.0'
+            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+            distribution 'repo'
           }
         }
       }
-      repositories.maven {
-        name 'sonatype'
-        if (version.endsWith('-SNAPSHOT')) {
-          url 'https://oss.sonatype.org/content/repositories/snapshots/'
-        } else {
-          url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
-        }
-
-        // It would be nice to pass a custom impl of PasswordCredentials
-        // that could lazily read username/password from the console if not
-        // present as properties. However, gradle's credential handling is
-        // completely broken for custom impls. It checks that the class
-        // passed in is exactly PasswordCredentials or AwsCredentials.
-        // So instead, we must rely on heuristics of "are we publishing"
-        // by inspecting the command line, stash the credentials
-        // once read in the root project, and set them on each project
-        if (gradle.startParameter.taskNames.contains('publish')) {
-          Console console = System.console()
-          if (project.rootProject.hasProperty('nexusUsername') == false) {
-            project.rootProject.ext.nexusUsername = console.readLine('\nNexus username: ')
-          }
-          if (project.rootProject.hasProperty('nexusPassword') == false) {
-            project.rootProject.ext.nexusPassword = new String(console.readPassword("\nNexus password: "))
+    }
+    extraArchive {
+      javadoc = true
+      tests = false
+    }
+    // we have our own username/password prompts so that they only happen once
+    // TODO: add gpg signing prompts
+    project.gradle.taskGraph.whenReady { taskGraph ->
+      if (taskGraph.allTasks.any { it.name == 'uploadArchives' }) {
+        Console console = System.console()
+        if (project.hasProperty('nexusUsername') == false) {
+          String nexusUsername = console.readLine('\nNexus username: ')
+          project.rootProject.allprojects.each {
+            it.ext.nexusUsername = nexusUsername
           }
-
-          credentials {
-            username = project.rootProject.nexusUsername 
-            password = project.rootProject.nexusPassword
+        }
+        if (project.hasProperty('nexusPassword') == false) {
+          String nexusPassword = new String(console.readPassword('\nNexus password: '))
+          project.rootProject.allprojects.each {
+            it.ext.nexusPassword = nexusPassword
           }
         }
       }
@@ -80,7 +72,6 @@ subprojects {
   }
 }
 
-
 allprojects {
   // injecting groovy property variables into all projects
   project.ext {

+ 0 - 1
buildSrc/.gitignore

@@ -1 +0,0 @@
-build-bootstrap/

+ 58 - 87
buildSrc/build.gradle

@@ -1,3 +1,5 @@
+import java.nio.file.Files
+
 /*
  * Licensed to Elasticsearch under one or more contributor
  * license agreements. See the NOTICE file distributed with
@@ -17,21 +19,25 @@
  * under the License.
  */
 
-import java.nio.file.Files
-
+// we must use buildscript + apply so that an external plugin
+// can apply this file, since the plugins directive is not
+// supported through file includes
+buildscript {
+  repositories {
+    jcenter()
+  }
+  dependencies {
+    classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
+  }
+}
 apply plugin: 'groovy'
+apply plugin: 'com.bmuschko.nexus'
+// TODO: move common IDE configuration to a common file to include
+apply plugin: 'idea'
+apply plugin: 'eclipse'
 
 group = 'org.elasticsearch.gradle'
-
-if (project == rootProject) {
-  // change the build dir used during build init, so that doing a clean
-  // won't wipe out the buildscript jar
-  buildDir = 'build-bootstrap'
-}
-
-/*****************************************************************************
- *         Propagating version.properties to the rest of the build           *
- *****************************************************************************/
+archivesBaseName = 'build-tools'
 
 Properties props = new Properties()
 props.load(project.file('version.properties').newDataInputStream())
@@ -45,29 +51,13 @@ if (snapshot) {
   props.put("elasticsearch", version);
 }
 
-File tempPropertiesFile = new File(project.buildDir, "version.properties")
-task writeVersionProperties {
-  inputs.properties(props)
-  doLast {
-    OutputStream stream = Files.newOutputStream(tempPropertiesFile.toPath());
-    try {
-      props.store(stream, "UTF-8");
-    } finally {
-      stream.close();
-    }
-  }
-}
-
-processResources {
-  dependsOn writeVersionProperties
-  from tempPropertiesFile
-}
-
-/*****************************************************************************
- *                    Dependencies used by the entire build                  *
- *****************************************************************************/
 
 repositories {
+  mavenCentral()
+  maven {
+    name 'sonatype-snapshots'
+    url "https://oss.sonatype.org/content/repositories/snapshots/"
+  }
   jcenter()
 }
 
@@ -79,7 +69,6 @@ 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....
@@ -88,67 +77,49 @@ dependencies {
   compile 'org.apache.rat:apache-rat:0.11'
 }
 
-
-/*****************************************************************************
- *                    Bootstrap repositories and IDE setup                   *
- *****************************************************************************/
-// this will only happen when buildSrc is built on its own during build init
-if (project == rootProject) {
-
-  repositories {
-    mavenCentral()
-    maven {
-      name 'sonatype-snapshots'
-      url "https://oss.sonatype.org/content/repositories/snapshots/"
+File tempPropertiesFile = new File(project.buildDir, "version.properties")
+task writeVersionProperties {
+  inputs.properties(props)
+  doLast {
+    OutputStream stream = Files.newOutputStream(tempPropertiesFile.toPath());
+    try {
+      props.store(stream, "UTF-8");
+    } finally {
+      stream.close();
     }
   }
+}
 
-  apply plugin: 'idea'
-  apply plugin: 'eclipse'
-
-  idea {
-    module {
-      inheritOutputDirs = false
-      outputDir = file('build-idea/classes/main')
-      testOutputDir = file('build-idea/classes/test')
-    }
-  }
+processResources {
+  dependsOn writeVersionProperties
+  from tempPropertiesFile
+}
 
-  eclipse {
-    classpath {
-      defaultOutputDir = file('build-eclipse')
-    }
-  }
+extraArchive {
+  javadoc = false
+  tests = false
+}
 
-  task copyEclipseSettings(type: Copy) {
-    from project.file('src/main/resources/eclipse.settings')
-    into '.settings'
-  }
-  // otherwise .settings is not nuked entirely
-  tasks.cleanEclipse {
-    delete '.settings'
+idea {
+  module {
+    inheritOutputDirs = false
+    outputDir = file('build-idea/classes/main')
+    testOutputDir = file('build-idea/classes/test')
   }
-  tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
 }
 
-/*****************************************************************************
- *                           Normal project checks                           *
- *****************************************************************************/
-
-// this happens when included as a normal project in the build, which we do
-// to enforce precommit checks like forbidden apis, as well as setup publishing
-if (project != rootProject) {
-  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 'build-tools'
-      }
-    }
+eclipse {
+  classpath {
+    defaultOutputDir = file('build-eclipse')
   }
 }
 
+task copyEclipseSettings(type: Copy) {
+  from project.file('src/main/resources/eclipse.settings')
+  into '.settings'
+}
+// otherwise .settings is not nuked entirely
+tasks.cleanEclipse {
+  delete '.settings'
+}
+tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)

+ 44 - 56
buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

@@ -32,8 +32,7 @@ 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.publish.maven.MavenPublication
-import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
+import org.gradle.api.artifacts.maven.MavenPom
 import org.gradle.api.tasks.bundling.Jar
 import org.gradle.api.tasks.compile.JavaCompile
 import org.gradle.internal.jvm.Jvm
@@ -61,6 +60,7 @@ 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)
@@ -68,7 +68,6 @@ class BuildPlugin implements Plugin<Project> {
         configureConfigurations(project)
         project.ext.versions = VersionProperties.versions
         configureCompile(project)
-        configurePublishing(project)
 
         configureTest(project)
         configurePrecommit(project)
@@ -261,6 +260,48 @@ 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 { 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)
+                    }
+                }
+            }
+        }
     }
 
     /** Adds repositores used by ES dependencies */
@@ -340,59 +381,6 @@ class BuildPlugin implements Plugin<Project> {
         }
     }
 
-    /**
-     * Adds a hook to all publications that will effectively make the maven pom transitive dependency free.
-     */
-    private static void configurePublishing(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 { 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)
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
     /** Returns a closure of common configuration shared by unit and integration tests. */
     static Closure commonTestConfig(Project project) {
         return {

+ 0 - 37
buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

@@ -18,14 +18,11 @@
  */
 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.publish.maven.MavenPublication
 import org.gradle.api.tasks.SourceSet
 import org.gradle.api.tasks.bundling.Zip
 
@@ -37,7 +34,6 @@ public class PluginBuildPlugin extends BuildPlugin {
     @Override
     public void apply(Project project) {
         super.apply(project)
-
         configureDependencies(project)
         // this afterEvaluate must happen before the afterEvaluate added by integTest creation,
         // so that the file name resolution for installing the plugin will be setup
@@ -54,10 +50,6 @@ 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)
-
-                if (project.pluginProperties.extension.publish) {
-                    configurePublishing(project)
-                }
             }
 
             project.namingConventions {
@@ -67,7 +59,6 @@ public class PluginBuildPlugin extends BuildPlugin {
         }
         createIntegTestTask(project)
         createBundleTask(project)
-        configurePublishing(project)
         project.tasks.create('run', RunTask) // allow running ES with this plugin in the foreground of a build
     }
 
@@ -134,32 +125,4 @@ 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 configurePublishing(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(name)
-                            } else if (node.name() == 'description') {
-                                node.setValue(project.pluginProperties.extension.description)
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-    }
 }

+ 0 - 4
buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy

@@ -42,10 +42,6 @@ class PluginPropertiesExtension {
     @Input
     boolean isolated = true
 
-    /** Whether the plugin should be published to maven. */
-    @Input
-    boolean publish = false
-
     PluginPropertiesExtension(Project project) {
         name = project.name
         version = project.version

+ 1 - 11
core/build.gradle

@@ -22,20 +22,10 @@ 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'
-apply plugin: 'nebula.source-jar'
-apply plugin: 'nebula.javadoc-jar'
 
 archivesBaseName = 'elasticsearch'
-publishing {
-  publications {
-    nebula {
-      artifactId 'elasticsearch'
-    }
-  }
-}
 
 dependencies {
 

+ 0 - 13
distribution/build.gradle

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

+ 1 - 8
distribution/deb/build.gradle

@@ -36,14 +36,7 @@ task buildDeb(type: Deb) {
 
 artifacts {
   'default' buildDeb
-}
-
-publishing {
-  publications {
-    nebula {
-      artifact buildDeb
-    }
-  }
+  archives buildDeb
 }
 
 integTest {

+ 1 - 8
distribution/integ-test-zip/build.gradle

@@ -24,14 +24,7 @@ task buildZip(type: Zip) {
 
 artifacts {
   'default' buildZip
-}
-
-publishing {
-  publications {
-    nebula {
-      artifact buildZip
-    }
-  }
+  archives buildZip
 }
 
 integTest.dependsOn buildZip

+ 1 - 8
distribution/rpm/build.gradle

@@ -33,14 +33,7 @@ task buildRpm(type: Rpm) {
 
 artifacts {
   'default' buildRpm
-}
-
-publishing {
-  publications {
-    nebula {
-      artifact buildRpm
-    }
-  }
+  archives buildRpm
 }
 
 integTest {

+ 1 - 8
distribution/tar/build.gradle

@@ -26,12 +26,5 @@ task buildTar(type: Tar) {
 
 artifacts {
   'default' buildTar
-}
-
-publishing {
-  publications {
-    nebula {
-      artifact buildTar
-    }
-  }
+  archives buildTar
 }

+ 1 - 8
distribution/zip/build.gradle

@@ -24,14 +24,7 @@ task buildZip(type: Zip) {
 
 artifacts {
   'default' buildZip
-}
-
-publishing {
-  publications {
-    nebula {
-      artifact buildZip
-    }
-  }
+  archives buildZip
 }
 
 integTest.dependsOn buildZip

+ 4 - 0
modules/build.gradle

@@ -40,4 +40,8 @@ subprojects {
       throw new InvalidModelException("Modules cannot disable isolation")
     }
   }
+
+  // these are implementation details of our build, no need to publish them!
+  install.enabled = false
+  uploadArchives.enabled = false
 }

+ 0 - 2
plugins/build.gradle

@@ -27,7 +27,5 @@ configure(subprojects.findAll { it.parent.path == project.path }) {
   esplugin {
     // for local ES plugins, the name of the plugin is the same as the directory
     name project.name
-    // only publish non examples
-    publish project.name.contains('example') == false
   }
 }

+ 0 - 3
settings.gradle

@@ -1,7 +1,6 @@
 rootProject.name = 'elasticsearch'
 
 List projects = [
-  'build-tools',
   'rest-api-spec',
   'core',
   'distribution:integ-test-zip',
@@ -60,8 +59,6 @@ if (isEclipse) {
 
 include projects.toArray(new String[0])
 
-project(':build-tools').projectDir = new File(rootProject.projectDir, 'buildSrc')
-
 if (isEclipse) {
   project(":core").projectDir = new File(rootProject.projectDir, 'core/src/main')
   project(":core").buildFileName = 'eclipse-build.gradle'

+ 0 - 5
test/build.gradle

@@ -40,9 +40,4 @@ subprojects {
   // TODO: why is the test framework pulled in...
   forbiddenApisMain.enabled = false
   jarHell.enabled = false
-
-  apply plugin: 'nebula.maven-base-publish'
-  apply plugin: 'nebula.maven-scm'
-  apply plugin: 'nebula.source-jar'
-  apply plugin: 'nebula.javadoc-jar'
 }