@@ -2,6 +2,8 @@ plugins {
2
2
id ' java'
3
3
id ' jacoco'
4
4
id ' nebula.release' version ' 13.0.0'
5
+ id ' maven-publish'
6
+ id ' signing'
5
7
}
6
8
7
9
group ' io.github.stefan-ka'
@@ -13,6 +15,10 @@ repositories {
13
15
mavenCentral()
14
16
}
15
17
18
+ if (! project. hasProperty(' signing.secretKeyRingFile' )) {
19
+ project. ext. ' signing.secretKeyRingFile' = " ${ rootDir} /secret-key.gpg"
20
+ }
21
+
16
22
dependencies {
17
23
implementation group : ' org.freemarker' , name : ' freemarker' , version : freemarkerVersion
18
24
@@ -21,6 +27,119 @@ dependencies {
21
27
testRuntimeOnly group : ' org.junit.jupiter' , name : ' junit-jupiter-engine' , version : jUnitVersion
22
28
}
23
29
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
+
24
143
test {
25
144
useJUnitPlatform()
26
145
}
@@ -33,3 +152,15 @@ jacocoTestReport {
33
152
}
34
153
35
154
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
+ }
0 commit comments