Skip to content

Commit 18105fa

Browse files
committed
Enable publication
1 parent a7037da commit 18105fa

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ jdk:
55

66
install: "/bin/true"
77

8-
script: ./gradlew clean build
8+
script:
9+
- |
10+
if [[ $TRAVIS_TAG =~ ^v.* ]]; then
11+
./gradlew clean build publish -Prelease.useLastTag=true -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE}
12+
else
13+
./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)
14+
fi
15+
16+
before_install:
17+
- openssl aes-256-cbc -K $encrypted_6e99b2392185_key -iv $encrypted_6e99b2392185_iv -in secret-key.gpg.enc -out secret-key.gpg -d
918

1019
after_success:
1120
- bash <(curl -s https://codecov.io/bash)

build.gradle

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
plugins {
22
id 'java'
33
id 'jacoco'
4+
id 'maven-publish'
5+
id 'signing'
6+
id 'nebula.release' version '13.0.0'
47
}
58

69
group 'org.contextmapper'
7-
version '1.0.0-SNAPSHOT'
810

911
sourceCompatibility = 1.8
1012

1113
repositories {
1214
mavenCentral()
1315
}
1416

17+
if (!project.hasProperty('signing.secretKeyRingFile')) {
18+
project.ext.'signing.secretKeyRingFile' = "${rootDir}/secret-key.gpg"
19+
}
20+
1521
dependencies {
1622
implementation 'org.reflections:reflections:0.9.11'
1723
implementation 'org.springframework.boot:spring-boot-autoconfigure:2.2.0.RELEASE'
@@ -25,6 +31,119 @@ dependencies {
2531
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
2632
}
2733

34+
task sourcesJar(type: Jar) {
35+
from sourceSets.main.allJava
36+
archiveClassifier = 'sources'
37+
}
38+
39+
task javadocJar(type: Jar) {
40+
from javadoc
41+
archiveClassifier = 'javadoc'
42+
}
43+
44+
artifacts {
45+
archives javadocJar, sourcesJar
46+
}
47+
48+
signing {
49+
sign configurations.archives
50+
required { gradle.taskGraph.hasTask("publishMavenJavaPublicationToMavenLocal") || gradle.taskGraph.hasTask("publishMavenJavaPublicationToMavenRepository") }
51+
}
52+
53+
publishing {
54+
publications {
55+
mavenJava(MavenPublication) {
56+
customizePom(pom)
57+
58+
artifactId = "${project.name}"
59+
groupId = "${project.group}"
60+
version = "${project.version}"
61+
from components.java
62+
artifact sourcesJar
63+
artifact javadocJar
64+
65+
pom.withXml {
66+
def pomFile = file("${project.buildDir}/generated-pom.xml")
67+
writeTo(pomFile)
68+
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
69+
artifact(pomAscFile) {
70+
classifier = null
71+
extension = 'pom.asc'
72+
}
73+
}
74+
75+
signArchives.signatures.each { signature ->
76+
artifact(signature) {
77+
def matcher = signature.file =~ /-(sources|javadoc)\.jar\.asc$/
78+
if (matcher.find()) {
79+
classifier = matcher.group(1)
80+
} else {
81+
classifier = null
82+
}
83+
extension = signature.type
84+
}
85+
}
86+
}
87+
}
88+
repositories {
89+
maven {
90+
def releasesRepoUrl = "${ossReleaseStagingRepository}"
91+
def snapshotsRepoUrl = "${ossSnapshotRepository}"
92+
url = project.version.toString().endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
93+
94+
credentials {
95+
username = System.getenv('OSSRH_USERNAME')
96+
password = System.getenv('OSSRH_PASSWORD')
97+
}
98+
}
99+
}
100+
}
101+
102+
def customizePom(pom) {
103+
pom.withXml {
104+
def root = asNode()
105+
106+
// eliminate test-scoped dependencies
107+
root.dependencies.removeAll { dep ->
108+
dep.scope == "test"
109+
}
110+
111+
root.children().last() + {
112+
resolveStrategy = Closure.DELEGATE_FIRST
113+
114+
description 'A reverse engineering library to generate Context Mapper DSL (CML) models from existing source code.'
115+
name 'Context Mapper DSL (CML) Discovery Library'
116+
url 'https://github.com/ContextMapper/context-map-discovery'
117+
organization {
118+
name 'Context Mapper'
119+
url 'https://contextmapper.org/'
120+
}
121+
issueManagement {
122+
system 'GitHub'
123+
url 'https://github.com/ContextMapper/context-map-discovery/issues'
124+
}
125+
licenses {
126+
license {
127+
name 'Apache License 2.0'
128+
url 'https://github.com/ContextMapper/service-cutter-library/blob/master/LICENSE'
129+
distribution 'repo'
130+
}
131+
}
132+
scm {
133+
url 'https://github.com/ContextMapper/context-map-discovery'
134+
connection 'scm:git:git://github.com/ContextMapper/context-map-discovery.git'
135+
developerConnection 'scm:git:ssh://git@github.com:ContextMapper/context-map-discovery.git'
136+
}
137+
developers {
138+
developer {
139+
name 'Stefan Kapferer'
140+
email 'stefan@contextmapper.org'
141+
}
142+
}
143+
}
144+
}
145+
}
146+
28147
test {
29148
useJUnitPlatform()
30149
}
@@ -37,3 +156,15 @@ jacocoTestReport {
37156
}
38157

39158
check.dependsOn jacocoTestReport
159+
160+
model {
161+
tasks.generatePomFileForMavenJavaPublication {
162+
destination = file("$buildDir/generated-pom.xml")
163+
}
164+
tasks.publishMavenJavaPublicationToMavenLocal {
165+
dependsOn project.tasks.signArchives
166+
}
167+
tasks.publishMavenJavaPublicationToMavenRepository {
168+
dependsOn project.tasks.signArchives
169+
}
170+
}

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# Publication repos
2+
ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/
3+
ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/
4+
15
# dependency versions
26
jUnitVersion=5.5.2

secret-key.gpg.enc

3.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)