Skip to content

Commit e3bc0d1

Browse files
committed
Setup publication process
1 parent 3cc89d2 commit e3bc0d1

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
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 snapshot
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_6dfdcbc02577_key -iv $encrypted_6dfdcbc02577_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: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ plugins {
22
id 'java'
33
id 'jacoco'
44
id 'nebula.release' version '13.0.0'
5+
id 'maven-publish'
6+
id 'signing'
57
}
68

79
group 'io.github.stefan-ka'
@@ -13,6 +15,10 @@ repositories {
1315
mavenCentral()
1416
}
1517

18+
if (!project.hasProperty('signing.secretKeyRingFile')) {
19+
project.ext.'signing.secretKeyRingFile' = "${rootDir}/secret-key.gpg"
20+
}
21+
1622
dependencies {
1723
implementation group: 'org.freemarker', name: 'freemarker', version: freemarkerVersion
1824

@@ -21,6 +27,119 @@ dependencies {
2127
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
2228
}
2329

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

35154
check.dependsOn jacocoTestReport
155+
156+
model {
157+
tasks.generatePomFileForMavenJavaPublication {
158+
destination = file("$buildDir/generated-pom.xml")
159+
}
160+
tasks.publishMavenJavaPublicationToMavenLocal {
161+
dependsOn project.tasks.signArchives
162+
}
163+
tasks.publishMavenJavaPublicationToMavenRepository {
164+
dependsOn project.tasks.signArchives
165+
}
166+
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
# Publication repos
2+
ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/
3+
ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/
4+
5+
# Dependency versions
16
jUnitVersion=5.6.2
27
freemarkerVersion=2.3.30

secret-key.gpg.enc

3.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)