Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

6.9 KB
Raw Blame
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Maven publications and configuration.
//
// the 'published' list contains an explicit list of all projects
// which should be published to Maven repositories.

configure(rootProject) {
  ext {
    published = [
        ":solr:api",
        ":solr:cross-dc-manager",
        ":solr:core",
        ":solr:solrj",
        ":solr:solrj-jetty",
        ":solr:solrj-streaming",
        ":solr:solrj-zookeeper",
        ":solr:test-framework",
    ] + project(":solr:modules").getChildProjects().values().path

    apacheNexusSnapshots = "https://repository.apache.org/content/repositories/snapshots"
  }
}

configure(subprojects.findAll {it.path in rootProject.published}) {prj ->
  apply plugin: 'maven-publish'
  apply plugin: 'signing'

  publishing {
    repositories {
      maven {
        name = "ApacheSnapshots"
        url = apacheNexusSnapshots

        credentials {
          def nexusUserName = rootProject.propertyOrDefault('asfNexusUsername', null)
          def nexusPwd = rootProject.propertyOrDefault('asfNexusPassword', null)
          if (nexusUserName && nexusPwd) {
            username nexusUserName
            password nexusPwd
          }
        }
      }
    }
  }

  // Do not generate gradle metadata files.
  tasks.withType(GenerateModuleMetadata) {
    enabled = false
  }

  plugins.withType(JavaPlugin) {
    task sourcesJar(type: Jar, dependsOn: classes) {
      archiveClassifier = 'sources'
      from sourceSets.main.allJava
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
      archiveClassifier = 'javadoc'
      from javadoc.destinationDir
    }

    // Add aliases of convention tasks with shorter names.
    task mavenToApacheSnapshots() {
      group "Publishing"
      description "Publish Maven JARs and POMs to Apache Snapshots repository: ${apacheNexusSnapshots}"

      dependsOn "publishJarsPublicationToApacheSnapshotsRepository"
    }

    publishing {
      def configurePom = {
        name = "Apache Solr (module: ${project.name})"
        description = name
        url = 'https://solr.apache.org/'

        licenses {
          license {
            name = 'Apache 2'
            url = 'https://apache.org/licenses/LICENSE-2.0.txt'
          }
        }

        inceptionYear = "2006"

        issueManagement {
          system = "JIRA"
          url = "https://issues.apache.org/jira/browse/SOLR"
        }

        ciManagement {
          system = "Jenkins"
          url = "https://builds.apache.org/job/Solr/"
        }

        mailingLists {
          mailingList {
            name = "Solr User List"
            subscribe = "[email protected]"
            unsubscribe = "[email protected]"
            archive = "https://lists.apache.org/[email protected]"
          }

          mailingList {
            name = "Solr Developer List"
            subscribe = "[email protected]"
            unsubscribe = "[email protected]"
            archive = "https://lists.apache.org/[email protected]"
          }

          mailingList {
            name = "Solr Commits List"
            subscribe = "[email protected]"
            unsubscribe = "[email protected]"
            archive = "https://lists.apache.org/[email protected]"
          }
        }

        scm {
          connection = 'scm:git:https://gitbox.apache.org/repos/asf/solr.git'
          developerConnection = 'scm:git:https://gitbox.apache.org/repos/asf/solr.git'
          url = 'https://gitbox.apache.org/repos/asf?p=solr.git'
        }
      }

      publications {
        jars(MavenPublication) {
          from components.java
          groupId = project.group
          artifactId = project.base.archivesName.get()

          artifact sourcesJar
          artifact javadocJar

          pom(configurePom)

          // Publish resolved/locked dependency versions instead of declared catalog versions
          versionMapping {
            usage('java-api') { fromResolutionOf('runtimeClasspath') }
            usage('java-runtime') { fromResolutionResult() }
          }

          // Remove the internal :platform dependency from dependencyManagement in POMs
          pom.withXml {
            def root = asNode()
            def depMgmt = root.dependencyManagement
            if (depMgmt) {
              depMgmt.each { dmNode ->
                def deps = dmNode.dependencies
                if (deps) {
                  deps.each { depsNode ->
                    // Collect dependencies to remove (can't modify while iterating)
                    def toRemove = []
                    depsNode.dependency.each { dep ->
                      def groupId = dep.groupId?.text()
                      def artifactId = dep.artifactId?.text()
                      if (groupId == 'org.apache' && artifactId == 'platform') {
                        toRemove.add(dep)
                      }
                    }
                    // Remove the collected dependencies
                    toRemove.each { dep ->
                      depsNode.remove(dep)
                    }
                    // Remove dependencyManagement section if it's now empty
                    if (depsNode.dependency.isEmpty()) {
                      root.remove(dmNode)
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    // This moves some configuration after all the scripts of all projects
    // have been evaluated. This is required because we compute some aspects dynamically and
    // maven pom does not accept lazy property providers (so everything must
    // be in its final form).
    //
    // In theory project.afterEvaluate closure should also work but for some reason
    // it fired earlier; don't know whether it's a bug
    // in gradle or just complex relationships between lazy collection hooks.
    gradle.projectsEvaluated {
      signing {
        if (project(":solr:distribution").ext.useGpgForSigning) {
          useGpgCmd()
        }
        required {project(":solr:distribution").ext.withSignedArtifacts}
        sign publishing.publications.jars
      }
    }
  }
}