1
1
import java.io.File
2
+ import java.util.*
2
3
3
4
plugins {
4
5
// Apply the application plugin to add support for building a CLI application in Java.
@@ -58,80 +59,6 @@ tasks.run.configure {
58
59
standardInput = System .`in `
59
60
}
60
61
61
- // https://docs.gradle.org/current/userguide/publishing_maven.html
62
- publishing {
63
- repositories {
64
- // Publish to GitHub Packages
65
- // https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-gradle
66
- maven {
67
- name = " GitHubPackages"
68
- url = uri(" https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe" )
69
- credentials {
70
- username = project.findProperty(" gpr.user" ) as String? ? : System .getenv(" GITHUB_ACTOR" )
71
- password = project.findProperty(" gpr.key" ) as String? ? : System .getenv(" GITHUB_TOKEN" )
72
- }
73
- }
74
- maven {
75
- name = " Sonatype"
76
- url = uri(
77
- if (version.toString().endsWith(" SNAPSHOT" ))
78
- " https://s01.oss.sonatype.org/content/repositories/snapshots/"
79
- else
80
- " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
81
- )
82
- credentials {
83
- username = project.findProperty(" sonatype.user" ) as String? ? : System .getenv(" SONATYPE_USER" )
84
- password = project.findProperty(" sonatype.key" ) as String? ? : System .getenv(" SONATYPE_TOKEN" )
85
- }
86
- }
87
- }
88
- publications {
89
- create<MavenPublication >(" maven" ) {
90
- groupId = " org.xxdc.oss.example"
91
- artifactId = " tictactoe-app"
92
- from(components[" java" ])
93
- pom {
94
- name.set(" tictactoe" )
95
- description.set(" An Over-Engineered Tic Tac Toe Game and Game Server" )
96
- url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
97
- licenses {
98
- license {
99
- name.set(" MIT License" )
100
- url.set(" https://opensource.org/licenses/MIT" )
101
- }
102
- developers {
103
- developer {
104
- id.set(" briancorbinxyz" )
105
- name.set(" Brian Corbin" )
106
- email.set(" mail@briancorbin.xyz" )
107
- }
108
- }
109
- }
110
- scm {
111
- connection.set(" scm:git:git://github.com/briancorbinxyz/overengineering-tictactoe.git" )
112
- developerConnection.set(" scm:git:ssh://github.com/briancorbinxyz/overengineering-tictactoe.git" )
113
- url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
114
- }
115
- }
116
- }
117
- }
118
- }
119
- // Signing
120
- afterEvaluate {
121
- // Check if we are running any kind of publish task
122
- val isPublishing = gradle.startParameter.taskNames.any { it.contains(" publish" , ignoreCase = true ) }
123
-
124
- if (isPublishing && project.hasProperty(" signing.key" )) {
125
- signing {
126
- useInMemoryPgpKeys(
127
- findProperty(" signing.keyId" ) as String? ,
128
- findProperty(" signing.key" ) as String? ,
129
- findProperty(" signing.password" ) as String?
130
- )
131
- sign(publishing.publications[" maven" ])
132
- }
133
- }
134
- }
135
62
// Install a pre-commit hook to run the Gradle task "spotlessApply" before committing changes.
136
63
tasks.register(" installGitHook" ) {
137
64
doLast {
@@ -223,3 +150,93 @@ if (enablePreviewFeatures) {
223
150
224
151
}
225
152
153
+ // https://docs.gradle.org/current/userguide/publishing_maven.html
154
+ publishing {
155
+ repositories {
156
+ // Publish to GitHub Packages
157
+ // https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-gradle
158
+ maven {
159
+ name = " Sonatype"
160
+ url = uri(
161
+ if (version.toString().endsWith(" SNAPSHOT" ))
162
+ " https://s01.oss.sonatype.org/content/repositories/snapshots/"
163
+ else
164
+ " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
165
+ )
166
+ credentials {
167
+ username = project.findProperty(" sonatype.user" ) as String? ? : System .getenv(" SONATYPE_USER" )
168
+ password = project.findProperty(" sonatype.key" ) as String? ? : System .getenv(" SONATYPE_TOKEN" )
169
+ }
170
+ }
171
+ maven {
172
+ name = " GitHubPackages"
173
+ url = uri(" https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe" )
174
+ credentials {
175
+ username = project.findProperty(" gpr.user" ) as String? ? : System .getenv(" GITHUB_ACTOR" )
176
+ password = project.findProperty(" gpr.key" ) as String? ? : System .getenv(" GITHUB_TOKEN" )
177
+ }
178
+ }
179
+ }
180
+ publications {
181
+ create<MavenPublication >(" maven" ) {
182
+ groupId = " org.xxdc.oss.example"
183
+ artifactId = " tictactoe-app"
184
+ from(components[" java" ])
185
+ pom {
186
+ name.set(" tictactoe" )
187
+ description.set(" An Over-Engineered Tic Tac Toe Game and Game Server" )
188
+ url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
189
+ licenses {
190
+ license {
191
+ name.set(" MIT License" )
192
+ url.set(" https://opensource.org/licenses/MIT" )
193
+ }
194
+ developers {
195
+ developer {
196
+ id.set(" briancorbinxyz" )
197
+ name.set(" Brian Corbin" )
198
+ email.set(" mail@briancorbin.xyz" )
199
+ }
200
+ }
201
+ }
202
+ scm {
203
+ connection.set(" scm:git:git://github.com/briancorbinxyz/overengineering-tictactoe.git" )
204
+ developerConnection.set(" scm:git:ssh://github.com/briancorbinxyz/overengineering-tictactoe.git" )
205
+ url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+ // Signing
212
+ fun decodeKey (raw : String ): String =
213
+ if (raw.contains(" -----BEGIN PGP PRIVATE KEY BLOCK-----" )) {
214
+ raw
215
+ } else {
216
+ String (Base64 .getDecoder().decode(raw))
217
+ }
218
+
219
+ val rawSigningKey = System .getenv(" SIGNING_KEY" ) ? : findProperty(" signing.key" ) as String?
220
+ val signingKey = rawSigningKey?.let (::decodeKey)
221
+
222
+ val signingPassword = System .getenv(" SIGNING_PASSWORD" ) ? : findProperty(" signing.password" ) as String?
223
+ val signingKeyId = System .getenv(" SIGNING_KEY_ID" ) ? : findProperty(" signing.keyId" ) as String?
224
+
225
+ val isPublishing = gradle.startParameter.taskNames.any { it.contains(" publish" , ignoreCase = true ) }
226
+
227
+ val shouldSign = isPublishing && signingKey != null && signingPassword != null
228
+
229
+ logger.lifecycle(" 🔐 Signing check:" )
230
+ logger.lifecycle(" • isPublishing: $isPublishing " )
231
+ logger.lifecycle(" • signingKeyId: ${signingKeyId != null } " )
232
+ logger.lifecycle(" • signingKey present: ${signingKey != null } " )
233
+ logger.lifecycle(" • signingPassword present: ${signingPassword != null } " )
234
+
235
+ if (shouldSign) {
236
+ signing {
237
+ useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
238
+ sign(publishing.publications)
239
+ }
240
+ } else {
241
+ logger.lifecycle(" ⚠️ Skipping signing: Not publishing or signing credentials are incomplete." )
242
+ }
0 commit comments