Skip to content

Commit 00c73da

Browse files
committed
add maven central publishing + secrets plugin
1 parent 23b764f commit 00c73da

File tree

6 files changed

+98
-50
lines changed

6 files changed

+98
-50
lines changed

build.gradle.kts

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66

77
id("me.modmuss50.mod-publish-plugin")
88
`maven-publish`
9+
id("com.gradleup.nmcp")
910

1011
id("dev.kikugie.postprocess.j52j") version "2.1-beta.3"
1112
}
@@ -151,7 +152,7 @@ val nativeTargets = listOf(
151152
val nativeConfigurations = nativeTargets.associate { target ->
152153
target.configurationName to configurations.create(target.configurationName)
153154
}
154-
val nativeHashConfiguration = configurations.create("nativeHashes")
155+
val nativeHashConfiguration: Configuration = configurations.create("nativeHashes")
155156

156157
nativeTargets.forEach { target ->
157158
dependencies {
@@ -242,42 +243,40 @@ publishMods {
242243
// modrinth and curseforge use different formats for snapshots. this can be expressed globally
243244
val stableMCVersions = versionList("pub.stableMC")
244245

245-
val modrinthId: String by project
246-
if (modrinthId.isNotBlank() && hasProperty("modrinth.token")) {
247-
modrinth {
248-
projectId.set(modrinthId)
249-
accessToken.set(findProperty("modrinth.token")?.toString())
250-
minecraftVersions.addAll(stableMCVersions)
251-
minecraftVersions.addAll(versionList("pub.modrinthMC"))
246+
modrinth {
247+
accessToken = secrets.gradleProperty("modrinth.accessToken")
252248

253-
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from Modrinth"
249+
projectId = providers.gradleProperty("pub.modrinthId")
254250

255-
requires { slug.set("yacl") }
251+
minecraftVersions.addAll(stableMCVersions)
252+
minecraftVersions.addAll(versionList("pub.modrinthMC"))
256253

257-
if (modstitch.isLoom) {
258-
requires { slug.set("fabric-api") }
259-
optional { slug.set("modmenu") }
260-
}
254+
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from Modrinth"
255+
256+
requires { slug.set("yacl") }
257+
258+
if (modstitch.isLoom) {
259+
requires { slug.set("fabric-api") }
260+
optional { slug.set("modmenu") }
261261
}
262262
}
263263

264-
val curseforgeId: String by project
265-
if (curseforgeId.isNotBlank() && hasProperty("curseforge.token")) {
266-
curseforge {
267-
projectId = curseforgeId
268-
projectSlug = findProperty("curseforgeSlug")!!.toString()
269-
accessToken = findProperty("curseforge.token")?.toString()
270-
minecraftVersions.addAll(stableMCVersions)
271-
minecraftVersions.addAll(versionList("pub.curseMC"))
264+
curseforge {
265+
accessToken = secrets.gradleProperty("curseforge.accessToken")
272266

273-
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from CurseForge"
267+
projectId = providers.gradleProperty("pub.curseforgeId")
268+
projectSlug = providers.gradleProperty("pub.curseforgeSlug")
274269

275-
requires { slug.set("yacl") }
270+
minecraftVersions.addAll(stableMCVersions)
271+
minecraftVersions.addAll(versionList("pub.curseMC"))
276272

277-
if (modstitch.isLoom) {
278-
requires { slug.set("fabric-api") }
279-
optional { slug.set("modmenu") }
280-
}
273+
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from CurseForge"
274+
275+
requires { slug.set("yacl") }
276+
277+
if (modstitch.isLoom) {
278+
requires { slug.set("fabric-api") }
279+
optional { slug.set("modmenu") }
281280
}
282281
}
283282
}
@@ -288,6 +287,33 @@ publishing {
288287

289288
artifactId = "controlify"
290289
groupId = "dev.isxander"
290+
291+
pom {
292+
name = modstitch.metadata.modName
293+
description = modstitch.metadata.modDescription
294+
url = "https://www.isxander.dev/projects/controlify"
295+
licenses {
296+
license {
297+
name = "LGPL-3.0-or-later"
298+
url = "https://www.gnu.org/licenses/lgpl-3.0.en.html"
299+
}
300+
}
301+
developers {
302+
developer {
303+
id = "isXander"
304+
name = "Xander"
305+
306+
}
307+
}
308+
scm {
309+
url = "https://github.com/isXander/Controlify"
310+
connection = "scm:git:git//github.com/isXander/Controlify.git"
311+
developerConnection = "scm:git:ssh://[email protected]/isXander/Controlify.git"
312+
}
313+
}
291314
}
292315
}
293316
}
317+
signing {
318+
sign(publishing.publications["mod"])
319+
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
fun plugin(id: String, version: String) = "$id:$id.gradle.plugin:$version"
3232

3333
implementation(plugin("dev.isxander.modstitch.base", "0.8.4"))
34+
implementation(plugin("dev.isxander.secrets", "0.1.0"))
3435
implementation(plugin("dev.kikugie.stonecutter", "0.8.2"))
3536
implementation(plugin("fabric-loom", "1.14.9"))
3637
implementation(plugin("net.neoforged.moddev", "2.0.137"))

buildSrc/src/main/kotlin/dev/isxander/controlify/project.gradle.kts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package dev.isxander.controlify
33
import net.fabricmc.loom.task.prod.ClientProductionRunTask
44

55
plugins {
6+
`java-library`
67
id("dev.isxander.modstitch.base")
78
`maven-publish`
8-
`java-library`
9+
signing
10+
id("dev.isxander.secrets")
911
}
1012

1113
modstitch.apply {
@@ -97,6 +99,10 @@ if (modstitch.isLoom) {
9799

98100
java {
99101
withSourcesJar()
102+
withJavadocJar()
103+
}
104+
tasks.javadoc {
105+
isFailOnError = false
100106
}
101107

102108
/*
@@ -143,22 +149,22 @@ tasks.named<ProcessResources>("generateModMetadata") {
143149
}
144150
}
145151

146-
val publishUsername = providers
147-
.gradleProperty("XANDER_MAVEN_USER")
148-
.orElse(providers.environmentVariable("XANDER_MAVEN_USER"))
149-
150-
val publishPassword = providers
151-
.gradleProperty("XANDER_MAVEN_PASS")
152-
.orElse(providers.environmentVariable("XANDER_MAVEN_PASS"))
153-
154-
155-
publishing {
156-
repositories {
157-
maven(url = "https://maven.isxander.dev/releases") {
158-
name = "XanderReleases"
159-
credentials(PasswordCredentials::class) {
160-
username = publishUsername.orNull
161-
password = publishPassword.orNull
152+
val signingKeyProvider = secrets.gradleProperty("signing.secretKey")
153+
val signingPasswordProvider = secrets.gradleProperty("signing.password")
154+
// not configuration cache friendly, but neither is the whole of signing plugin
155+
// this plugin does not support lazy configuration of signing keys
156+
gradle.taskGraph.whenReady {
157+
val willSign = allTasks.any { it.name.startsWith("sign") }
158+
if (willSign) {
159+
signing {
160+
val signingKey = signingKeyProvider.orNull
161+
val signingPassword = signingPasswordProvider.orNull
162+
163+
isRequired = signingKey != null && signingPassword != null
164+
if (isRequired) {
165+
useInMemoryPgpKeys(signingKey, signingPassword)
166+
} else {
167+
logger.error("Signing keys not found; skipping signing!")
162168
}
163169
}
164170
}

gradle.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
org.gradle.jvmargs=-Xmx4G
22
org.gradle.parallel=true
3-
org.gradle.configuration-cache=true
43

54
modVersion=2.5.0
65
modId=controlify
76
modName=Controlify
87
modDescription=The most advanced controller mod for Minecraft.
98

10-
curseforgeId=835847
11-
curseforgeSlug=controlify
12-
modrinthId=DOUdJVEm
9+
pub.curseforgeId=835847
10+
pub.curseforgeSlug=controlify
11+
pub.modrinthId=DOUdJVEm
1312
githubProject=isXander/Controlify
1413

1514
deps.fabricLoader=0.18.4

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pluginManagement {
2525
}
2626

2727
plugins {
28-
id("dev.kikugie.stonecutter") version "0.8.1"
28+
id("dev.kikugie.stonecutter") version "0.8.2"
2929
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
3030
}
3131

stonecutter.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ plugins {
55
id("dev.kikugie.stonecutter")
66
id("de.undercouch.download") version "5.6.0"
77
id("org.moddedmc.wiki.toolkit") version "0.2.5"
8+
id("com.gradleup.nmcp.aggregation") version "1.4.3"
9+
id("dev.isxander.secrets")
810

911
id("dev.isxander.modstitch.base") apply false
1012
}
@@ -68,6 +70,20 @@ publishMods {
6870
)
6971
}
7072

73+
nmcpAggregation {
74+
centralPortal {
75+
username = secrets.gradleProperty("mcentral.username")
76+
password = secrets.gradleProperty("mcentral.password")
77+
78+
publicationName = "controlify:$version"
79+
}
80+
}
81+
dependencies {
82+
allprojects {
83+
nmcpAggregation(project(path))
84+
}
85+
}
86+
7187
wiki {
7288
docs {
7389
register("controlify") {

0 commit comments

Comments
 (0)