diff --git a/.travis.yml b/.travis.yml index 3fc5297..b534f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,16 @@ jdk: install: "/bin/true" -script: ./gradlew clean build +script: + - | + if [[ $TRAVIS_TAG =~ ^v.* ]]; then + ./gradlew clean build publish -Prelease.useLastTag=true -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE} + else + ./gradlew clean build snapshot $(if [[ $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo "publish -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE}"; fi) + fi + +before_install: +- openssl aes-256-cbc -K $encrypted_6e99b2392185_key -iv $encrypted_6e99b2392185_iv -in secret-key.gpg.enc -out secret-key.gpg -d after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/build.gradle b/build.gradle index 1b24cdf..d004167 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,12 @@ plugins { id 'java' id 'jacoco' + id 'maven-publish' + id 'signing' + id 'nebula.release' version '13.0.0' } group 'org.contextmapper' -version '1.0.0-SNAPSHOT' sourceCompatibility = 1.8 @@ -12,6 +14,10 @@ repositories { mavenCentral() } +if (!project.hasProperty('signing.secretKeyRingFile')) { + project.ext.'signing.secretKeyRingFile' = "${rootDir}/secret-key.gpg" +} + dependencies { implementation 'org.reflections:reflections:0.9.11' implementation 'org.springframework.boot:spring-boot-autoconfigure:2.2.0.RELEASE' @@ -25,6 +31,119 @@ dependencies { testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion } +task sourcesJar(type: Jar) { + from sourceSets.main.allJava + archiveClassifier = 'sources' +} + +task javadocJar(type: Jar) { + from javadoc + archiveClassifier = 'javadoc' +} + +artifacts { + archives javadocJar, sourcesJar +} + +signing { + sign configurations.archives + required { gradle.taskGraph.hasTask("publishMavenJavaPublicationToMavenLocal") || gradle.taskGraph.hasTask("publishMavenJavaPublicationToMavenRepository") } +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + + artifactId = "${project.name}" + groupId = "${project.group}" + version = "${project.version}" + from components.java + artifact sourcesJar + artifact javadocJar + + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + signArchives.signatures.each { signature -> + artifact(signature) { + def matcher = signature.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = signature.type + } + } + } + } + repositories { + maven { + def releasesRepoUrl = "${ossReleaseStagingRepository}" + def snapshotsRepoUrl = "${ossSnapshotRepository}" + url = project.version.toString().endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + + credentials { + username = System.getenv('OSSRH_USERNAME') + password = System.getenv('OSSRH_PASSWORD') + } + } + } +} + +def customizePom(pom) { + pom.withXml { + def root = asNode() + + // eliminate test-scoped dependencies + root.dependencies.removeAll { dep -> + dep.scope == "test" + } + + root.children().last() + { + resolveStrategy = Closure.DELEGATE_FIRST + + description 'A reverse engineering library to generate Context Mapper DSL (CML) models from existing source code.' + name 'Context Mapper DSL (CML) Discovery Library' + url 'https://github.com/ContextMapper/context-map-discovery' + organization { + name 'Context Mapper' + url 'https://contextmapper.org/' + } + issueManagement { + system 'GitHub' + url 'https://github.com/ContextMapper/context-map-discovery/issues' + } + licenses { + license { + name 'Apache License 2.0' + url 'https://github.com/ContextMapper/service-cutter-library/blob/master/LICENSE' + distribution 'repo' + } + } + scm { + url 'https://github.com/ContextMapper/context-map-discovery' + connection 'scm:git:git://github.com/ContextMapper/context-map-discovery.git' + developerConnection 'scm:git:ssh://git@github.com:ContextMapper/context-map-discovery.git' + } + developers { + developer { + name 'Stefan Kapferer' + email 'stefan@contextmapper.org' + } + } + } + } +} + test { useJUnitPlatform() } @@ -37,3 +156,15 @@ jacocoTestReport { } check.dependsOn jacocoTestReport + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} diff --git a/gradle.properties b/gradle.properties index e67abdf..77bc4eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ +# Publication repos +ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/ +ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/ + # dependency versions jUnitVersion=5.5.2 diff --git a/secret-key.gpg.enc b/secret-key.gpg.enc new file mode 100644 index 0000000..8c564c6 Binary files /dev/null and b/secret-key.gpg.enc differ