blob: b08ccd12c658887494edee47b69ac03292c6b338 [file] [log] [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.
*/
// Configure artifact push to apache nexus (releases repository).
configure(rootProject) {
ext {
apacheNexusReleasesRepository = "https://repository.apache.org/service/local/staging/deploy/maven2"
}
// These access credentials must be passed by the release manager
// (either on command-line, via the environment or via ~/.gradle.properties).
def asfNexusUsername = propertyOrEnvOrDefault('asfNexusUsername', "ASF_NEXUS_USERNAME", null)
def asfNexusPassword = propertyOrEnvOrDefault('asfNexusPassword', "ASF_NEXUS_PASSWORD", null)
task mavenToApacheReleases() {
group "Distribution"
description "Publish Lucene Maven artifacts to Apache Releases repository: ${apacheNexusReleasesRepository}"
dependsOn rootProject.ext.mavenProjects.collect {
it.tasks.matching { it.name == "publishSignedJarsPublicationToApacheReleasesRepository" }
}
}
task checkReleasesRepositoryPushPreconditions() {
doFirst {
// Make sure we're pushing a release version. The release repository
// does not accept snapshots and returns cryptic errors upon trying.
if (snapshotBuild) {
throw new GradleException("ASF releases repository will not accept a snapshot version: ${rootProject.version}")
}
// Make sure access credentials have been passed.
if (asfNexusUsername == null || asfNexusPassword == null) {
throw new GradleException("asfNexusUsername or asfNexusPassword is empty: these are required to publish to " +
" ASF Nexus.")
}
}
}
configure(rootProject.ext.mavenProjects) { Project project ->
// Make sure any actual publication task is preceded by precondition checks.
tasks.matching { it.name ==~ /publish.+ToApacheReleasesRepository/ }.all {
dependsOn rootProject.tasks.checkReleasesRepositoryPushPreconditions
}
// Configure the release repository.
plugins.withType(PublishingPlugin) {
publishing {
repositories {
maven {
name = "ApacheReleases"
url = apacheNexusReleasesRepository
credentials {
username asfNexusUsername
password asfNexusPassword
}
}
}
}
}
}
}