Skip to content

Commit

Permalink
Use maven-publish plugin for publishing (spockframework#950)
Browse files Browse the repository at this point in the history
This commit changes the build's publishing from the old `maven` plugin
to the new `maven-publish` plugin.
  • Loading branch information
marcphilipp authored and leonard84 committed Nov 18, 2018
1 parent f51c3ed commit 36b015b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 177 deletions.
23 changes: 1 addition & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ apply from: script("ide")
subprojects {
apply plugin: "groovy"
apply plugin: "jacoco"
apply plugin: "signing"

sourceCompatibility = javaVersions.min()
targetCompatibility = javaVersions.min()
Expand Down Expand Up @@ -143,22 +142,6 @@ subprojects {
compile(project.name == "spock-gradle" ? [] : libs.groovy)
}

signing {
required { gradle.taskGraph.hasTask(':uploadArchives') }
sign configurations.archives
}

signArchives {
onlyIf { gradle.taskGraph.hasTask(':uploadArchives') }
}

ext."signing.keyId" = "2EA0A67F"
if (System.getenv("SIGNING_PASSWORD")) {
// if the password property is set, even if its null null, the SigningExtension will try to load the key
ext."signing.password" = System.getenv("SIGNING_PASSWORD")
}
ext."signing.secretKeyRingFile" = "$rootDir/config/code-signing-secring.gpg"

configureJavadoc(javadoc)
configureGroovydoc(groovydoc)

Expand All @@ -172,10 +155,6 @@ subprojects {
from javadoc
}

artifacts {
archives sourcesJar, javadocJar
}

tasks.withType(Test) {
def taskName = name
reports {
Expand Down Expand Up @@ -257,7 +236,7 @@ if (gradle.startParameter.taskNames == ["travisCiBuild"]) {
}
if (System.getenv("TRAVIS_PULL_REQUEST") == "false" && System.getenv("TRAVIS_BRANCH") == "master") {
if (javaVersion == javaVersions.min()) {
gradle.startParameter.taskNames += ["uploadArchives"]
gradle.startParameter.taskNames += ["publish"]
if (!snapshotVersion) {
gradle.startParameter.taskNames += ["tagRelease"]
}
Expand Down
150 changes: 74 additions & 76 deletions gradle/publishMaven.gradle
Original file line number Diff line number Diff line change
@@ -1,92 +1,90 @@
apply plugin: "maven"
apply plugin: "maven-publish"
apply plugin: "signing"

def basePom = {
project {
name project.ext.displayName
description project.description
url "http://spockframework.org"

licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
def optionalDeps = []
def providedDeps = []

scm {
connection "scm:git:git://github.com/spockframework/spock.git"
developerConnection "scm:git:ssh://git@github.com/spockframework/spock.git"
url "http://github.spockframework.org/spock"
}
ext {
optional = { optionalDeps << it; it }
provided = { providedDeps << it; it }
}

developers {
developer {
id "pniederw"
name "Peter Niederwieser"
email "peter@pniederw.com"
publishing {
publications {
maven(MavenPublication) {
from(components.java)
afterEvaluate {
if (pom.packaging != "pom") {
artifact(sourcesJar)
artifact(javadocJar)
}
}

developer {
id "ldaley"
name "Luke Daley"
email "ld@ldaley.com"
pom {
name = provider { project.ext.displayName }
description = provider { project.description }
url = "http://spockframework.org"
licenses {
license {
name = "The Apache Software License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "repo"
}
}
scm {
connection = "scm:git:git://github.com/spockframework/spock.git"
developerConnection = "scm:git:ssh://git@github.com/spockframework/spock.git"
url = "http://github.spockframework.org/spock"
}
developers {
developer {
id = "pniederw"
name = "Peter Niederwieser"
email = "peter@pniederw.com"
}
developer {
id = "ldaley"
name = "Luke Daley"
email = "ld@ldaley.com"
}
}
afterEvaluate {
withXml {
def dependencies = asNode().dependencies[0]
optionalDeps.each { dep ->
dependencies.find { it.artifactId.text() == dep.name }.appendNode("optional", true)
}
providedDeps.each { dep ->
dependencies.find { it.artifactId.text() == dep.name }.scope[0].value = "provided"
}
}
}
}
}
}
}

def deployers = []

project.afterEvaluate {
configure(deployers) {
pom basePom
}
}

install {
deployers << repositories.mavenInstaller
}

uploadArchives {
deployers << repositories.mavenDeployer {
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: "pniederw", password: System.getenv("SONATYPE_OSS_PASSWORD"))
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: "pniederw", password: System.getenv("SONATYPE_OSS_PASSWORD"))
repositories {
maven {
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
url = snapshotVersion ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = "pniederw"
password = System.getenv("SONATYPE_OSS_PASSWORD")
}
}
}
}

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 }
// ensure all checks pass before publishing
tasks.withType(AbstractPublishToMaven) {
dependsOn(check)
}

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 }
signing {
sign(publishing.publications).each { task ->
task.onlyIf { gradle.taskGraph.hasTask(publish) }
}
// no need to publish test dependencies
pom.dependencies.removeAll { it.scope == "test" }
}

deployers*.beforeDeployment { signing.signPom(it) }
ext."signing.keyId" = "2EA0A67F"
ext."signing.password" = System.getenv("SIGNING_PASSWORD")
ext."signing.secretKeyRingFile" = "$rootDir/config/code-signing-secring.gpg"
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ def nameBuildScriptsAfterProjectNames(projects) {
nameBuildScriptsAfterProjectNames(prj.children)
}
}

enableFeaturePreview("STABLE_PUBLISHING")
77 changes: 6 additions & 71 deletions spock-bom/bom.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
plugins {
id 'maven'
}
apply from: script("publishMaven")

def modifyBom = { xml ->
def projectNode = xml.asNode()

projectNode.remove(projectNode['dependencies'][0]) // remove default dependency section

projectNode['version'] + { // add packaging next to version
packaging 'pom'
}

projectNode.appendNode('properties').appendNode('spock.version', project.fullVersion)

def dependencyManagement = projectNode.appendNode('dependencyManagement').appendNode('dependencies')

def mvnProjects = project.parent.subprojects.findAll { it.hasProperty('install') } // find all published projects
def mvnProjects = project.parent.subprojects.findAll { it.plugins.hasPlugin('maven-publish') } // find all published projects
mvnProjects -= project // don't self reference

String groupId = project.group
Expand All @@ -32,68 +26,9 @@ ext.displayName = "Spock Framework - Bill of Materials"

description = '''This bill of materials provides managed spock dependencies.'''

def bom = {
project {
name project.ext.displayName
description project.description
url "http://spockframework.org"

licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}

scm {
connection "scm:git:git://github.com/spockframework/spock.git"
developerConnection "scm:git:ssh://git@github.com/spockframework/spock.git"
url "http://github.spockframework.org/spock"
}

developers {
developer {
id "pniederw"
name "Peter Niederwieser"
email "peter@pniederw.com"
}

developer {
id "ldaley"
name "Luke Daley"
email "ld@ldaley.com"
}
}
}
}
task writeBom {
doLast {
pom(bom).withXml(modifyBom) .writeTo("$buildDir/pom.xml")
}
}

def deployers = []

project.afterEvaluate {
configure(deployers) {
pom(bom).withXml(modifyBom)
}
}

install {
deployers << repositories.mavenInstaller
}

uploadArchives {
deployers << repositories.mavenDeployer {
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: "pniederw", password: System.getenv("SONATYPE_OSS_PASSWORD"))
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: "pniederw", password: System.getenv("SONATYPE_OSS_PASSWORD"))
}
publishing.publications.maven {
pom {
packaging = 'pom'
withXml modifyBom
}
}

deployers*.beforeDeployment { signing.signPom(it) }
2 changes: 0 additions & 2 deletions spock-guice/guice.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ description = "Spock's Guice Module provides support for testing Guice 2/3 based
dependencies {
compile project(":spock-core")
compile "com.google.inject:guice:3.0", provided
// surfaces in the Guice API; groovyc complains if we don't add it
compile "aopalliance:aopalliance:1.0", internal
}

jar {
Expand Down
6 changes: 0 additions & 6 deletions spock-unitils/unitils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ dependencies {
compile project(":spock-core")
compile "org.unitils:unitils-core:3.3"

// the following are transitive deps of unitils-core with scope compile
// nevertheless, if we don't specify them explicitely, groovyc crashes with
// NoClassDefFoundError at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:285)
compile "commons-collections:commons-collections:3.2", internal
compile "ognl:ognl:2.6.9", internal

testCompile "org.unitils:unitils-dbunit:3.3", {
exclude module: "jta"
}
Expand Down

0 comments on commit 36b015b

Please sign in to comment.