apply plugin: "maven" def basePom = { project { name project.displayName packaging 'bundle' description project.description url 'https://github.com/jayway/JsonPath' licenses { license { name "The Apache Software License, Version 2.0" url "http://www.apache.org/licenses/LICENSE-2.0.txt" distribution "repo" } } scm { url 'scm:git:git://github.com/jayway/JsonPath.git' connection 'scm:git:git://github.com/jayway/JsonPath.git' developerConnection 'scm:git:git://github.com/jayway/JsonPath.git' } developers { developer { id 'kalle.stenflo' name 'Kalle Stenflo' email 'kalle.stenflo (a) gmail.com' } } } } def deployers = [] project.afterEvaluate { configure(deployers) { pom basePom } } install { deployers << repositories.mavenInstaller } uploadArchives { deployers << repositories.mavenDeployer { if (snapshotVersion) { snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { if (project.hasProperty("sonatypeOssUsername")) { authentication(userName: sonatypeOssUsername, password: sonatypeOssPassword) } } } else { repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { if (project.hasProperty("sonatypeOssUsername")) { authentication(userName: sonatypeOssUsername, password: sonatypeOssPassword) } } } } } def poms = deployers*.pom def optionalDeps = [] def providedDeps = [] def internalDeps = [] ext { modifyPom = { Closure modification -> poms.each { it.whenConfigured(modification) } } optional = { optionalDeps << it; it } provided = { providedDeps << it; it } internal = { internalDeps << it; it } } modifyPom { pom -> optionalDeps.each { dep -> pom.dependencies.find { it.artifactId == dep.name }.optional = true } providedDeps.each { dep -> pom.dependencies.find { it.artifactId == dep.name }.scope = "provided" } internalDeps.each { dep -> pom.dependencies.removeAll { it.artifactId == dep.name } } // no need to publish test dependencies pom.dependencies.removeAll { it.scope == "test" } } deployers*.beforeDeployment { signing.signPom(it) }