1
- import java.io.File
2
1
import java.util.*
2
+ import com.vanniktech.maven.publish.SonatypeHost
3
3
4
4
plugins {
5
5
id(" buildlogic.java-library-conventions" )
6
- signing
6
+ // Apply the maven-publish plugin from com.vanniktech for publishing to repositories
7
+ id(" com.vanniktech.maven.publish" )
7
8
}
8
9
10
+ group = " org.xxdc.oss.example"
11
+
9
12
val libPath = " native/src/main/rust/target/debug"
10
13
val osName = System .getProperty(" os.name" ).lowercase()
11
14
val osArch = System .getProperty(" os.arch" ).lowercase()
@@ -40,13 +43,6 @@ tasks.register<JavaExec>("jmh") {
40
43
args = listOf (" org.xxdc.oss.example.interop.benchmark.PlayerIdsBenchmark" )
41
44
}
42
45
43
- java {
44
- withJavadocJar()
45
- withSourcesJar()
46
- }
47
-
48
-
49
-
50
46
// TODO: Disable preview features on the branch when the next JDK is released
51
47
val enablePreviewFeatures = true
52
48
@@ -81,97 +77,36 @@ if (enablePreviewFeatures) {
81
77
}
82
78
}
83
79
}
84
- // https://docs.gradle.org/current/userguide/publishing_maven.html
80
+
81
+ // Publishing
82
+ mavenPublishing {
83
+ publishToMavenCentral(SonatypeHost .CENTRAL_PORTAL )
84
+ val signingKey = (findProperty(" signingInMemoryKey" ) ? : findProperty(" signing.key" )) as String?
85
+ // if (signingKey != null) {
86
+ if (false ) {
87
+ signAllPublications()
88
+ }
89
+
90
+ coordinates (
91
+ project.group as String? ,
92
+ " tictactoe-api" ,
93
+ project.version as String?
94
+ )
95
+ pom {
96
+ name.set(" tictactoe-api" )
97
+ description.set(" An Over-Engineered Tic Tac Toe Game API" )
98
+ }
99
+ }
100
+
85
101
publishing {
86
102
repositories {
87
- // Publish to GitHub Packages
88
- // https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-gradle
89
- val targetRepo: String? = findProperty(" repo" ) as String?
90
- if (targetRepo == null || targetRepo == " Sonatype" ) {
91
- maven {
92
- name = " Sonatype"
93
- url = uri(
94
- if (version.toString().endsWith(" SNAPSHOT" ))
95
- // "https://s01.oss.sonatype.org/content/repositories/snapshots/"
96
- " https://central.sonatype.com/repository/maven-snapshots/"
97
- else
98
- // "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
99
- " https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2"
100
- )
101
- credentials {
102
- username = project.findProperty(" sonatype.user" ) as String? ? : System .getenv(" SONATYPE_USER" )
103
- password = project.findProperty(" sonatype.key" ) as String? ? : System .getenv(" SONATYPE_TOKEN" )
104
- }
105
- }
106
- }
107
- if (targetRepo == null || targetRepo == " GitHubPackages" ) {
108
- maven {
109
- name = " GitHubPackages"
110
- url = uri(" https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe" )
111
- credentials {
112
- username = project.findProperty(" gpr.user" ) as String? ? : System .getenv(" GITHUB_ACTOR" )
113
- password = project.findProperty(" gpr.key" ) as String? ? : System .getenv(" GITHUB_TOKEN" )
114
- }
115
- }
116
- }
117
- }
118
- publications {
119
- create<MavenPublication >(" maven" ) {
120
- groupId = " org.xxdc.oss.example"
121
- artifactId = " tictactoe-api"
122
- from(components[" java" ])
123
- pom {
124
- name.set(" tictactoe" )
125
- description.set(" An Over-Engineered Tic Tac Toe Game API" )
126
- url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
127
- licenses {
128
- license {
129
- name.set(" MIT License" )
130
- url.set(" https://opensource.org/licenses/MIT" )
131
- }
132
- developers {
133
- developer {
134
- id.set(" briancorbinxyz" )
135
- name.set(" Brian Corbin" )
136
- email.set(" mail@briancorbin.xyz" )
137
- }
138
- }
139
- }
140
- scm {
141
- connection.set(" scm:git:git://github.com/briancorbinxyz/overengineering-tictactoe.git" )
142
- developerConnection.set(" scm:git:ssh://github.com/briancorbinxyz/overengineering-tictactoe.git" )
143
- url.set(" https://github.com/briancorbinxyz/overengineering-tictactoe" )
144
- }
103
+ maven {
104
+ name = " GitHubPackages"
105
+ url = uri(" https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe" )
106
+ credentials {
107
+ username = findProperty(" gpr.user" ) as String? ? : System .getenv(" GITHUB_ACTOR" )
108
+ password = findProperty(" gpr.key" ) as String? ? : System .getenv(" GITHUB_TOKEN" )
145
109
}
146
110
}
147
111
}
148
112
}
149
- fun decodeKey (raw : String ): String =
150
- if (raw.contains(" -----BEGIN PGP PRIVATE KEY BLOCK-----" )) {
151
- raw
152
- } else {
153
- String (Base64 .getDecoder().decode(raw))
154
- }
155
-
156
- val rawSigningKey = System .getenv(" SIGNING_KEY" ) ? : findProperty(" signing.key" ) as String?
157
- val signingKey = rawSigningKey?.let (::decodeKey)
158
-
159
- val signingPassword = System .getenv(" SIGNING_PASSWORD" ) ? : findProperty(" signing.password" ) as String?
160
- val signingKeyId = System .getenv(" SIGNING_KEY_ID" ) ? : findProperty(" signing.keyId" ) as String?
161
-
162
- val isPublishing = gradle.startParameter.taskNames.any { it.contains(" publish" , ignoreCase = true ) }
163
-
164
- val shouldSign = signingKey != null && signingPassword != null
165
-
166
- logger.lifecycle(" 🔐 Signing check:" )
167
- logger.lifecycle(" • isPublishing: $isPublishing " )
168
- logger.lifecycle(" • signingKeyId: ${signingKeyId != null } " )
169
- logger.lifecycle(" • signingKey present: ${signingKey != null } " )
170
- logger.lifecycle(" • signingPassword present: ${signingPassword != null } " )
171
- logger.lifecycle(" • shouldSign: $shouldSign " )
172
- if (isPublishing && shouldSign) {
173
- signing {
174
- useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
175
- sign(configurations.runtimeElements.get())
176
- }
177
- }
0 commit comments