Skip to content

Commit

Permalink
Enable publication
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-ka committed Oct 29, 2019
1 parent a7037da commit 18105fa
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
133 changes: 132 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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

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'
Expand All @@ -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://[email protected]:ContextMapper/context-map-discovery.git'
}
developers {
developer {
name 'Stefan Kapferer'
email '[email protected]'
}
}
}
}
}

test {
useJUnitPlatform()
}
Expand All @@ -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
}
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Binary file added secret-key.gpg.enc
Binary file not shown.

0 comments on commit 18105fa

Please sign in to comment.