Skip to content

Commit 6271504

Browse files
committed
migrate to modpublisher
1 parent b185d68 commit 6271504

4 files changed

Lines changed: 98 additions & 204 deletions

File tree

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ jobs:
127127
env:
128128
CURSEFORGE: ${{ secrets.CURSEFORGE }}
129129
IS_PIPELINE: true
130-
run: gradle publishCurseForge
130+
run: gradle publishCurseforge
131131

132132
- name: 📤 Create GitHub Release
133133
env:
134134
GITHUB: ${{ secrets.GITHUB_TOKEN }}
135135
IS_PIPELINE: true
136-
run: gradle publishGithubRelease
136+
run: gradle publishGithub
137137

138138
- name: 🧨 Cleanup Gradle cache
139139
run: |

build.gradle

Lines changed: 77 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ plugins {
22
id 'groovy'
33
id 'fabric-loom' version "${loom_version}"
44
id 'maven-publish'
5-
id "com.modrinth.minotaur" version "2.+"
6-
id 'io.github.themrmilchmann.curseforge-publish' version "0.8.0"
7-
id "com.github.breadmoirai.github-release" version "2.3.7"
5+
id "com.hypherionmc.modutils.modpublisher" version "2.1.6"
86
// id 'checkstyle'
97
}
108

@@ -27,7 +25,6 @@ allprojects {
2725
apply plugin: 'fabric-loom'
2826
apply plugin: 'idea'
2927

30-
3128
group = project.maven_group
3229
String vers_suffix = getenv("VERSION_SUFFIX")
3330
String full_version = vers_suffix != 'NOT FOUND' && vers_suffix != ''
@@ -54,44 +51,32 @@ allprojects {
5451

5552
subprojects.each {
5653
implementation project(path: ":${it.name}", configuration: "namedElements")
57-
include project("${it.name}:") // nest within distribution
54+
include project("${it.name}:")
5855
}
5956
}
6057

61-
// Perform tests using the JUnit test suite
6258
test {
6359
useJUnitPlatform()
6460
}
6561

66-
// Produce a sources distribution
6762
java {
6863
withSourcesJar()
6964
}
7065

71-
// Add the licence to all distributions
7266
tasks.withType(Jar).configureEach {
7367
it.from rootProject.file('LICENCE')
7468
}
7569

76-
// Process any resources
7770
processResources {
7871
inputs.property 'id', project.mod_id
7972
inputs.property 'name', project.mod_name
8073
inputs.property 'version', project.version
8174

82-
// fabric.mod.json
8375
filesMatching('fabric.mod.json') {
8476
expand(['id': project.mod_id, 'name': project.mod_name, 'version': project.version])
8577
}
8678
}
8779

88-
// checkstyle {
89-
// // use one common config file for all subprojects
90-
// configFile = project(':').file('.checkstyle.xml')
91-
// configProperties = [ "suppressionFile" : project(':').file('.checkstyle-suppressions.xml')]
92-
// }
93-
94-
// Add any additional repositories
9580
repositories {
9681
gradlePluginPortal()
9782
mavenCentral()
@@ -103,9 +88,7 @@ allprojects {
10388
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
10489
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
10590
// for more information about repositories.
106-
maven { url 'https://maven.nucleoid.xyz' }
107-
// Used by FabricPlaceholderAPI
108-
91+
maven { url 'https://maven.nucleoid.xyz' } // Used by FabricPlaceholderAPI
10992
maven {
11093
name = 'Ladysnake Mods'
11194
url = 'https://maven.ladysnake.org/releases'
@@ -118,9 +101,8 @@ allprojects {
118101
}
119102
}
120103

121-
// Root project specific dependencies
104+
// Root-project-specific dependencies
122105
dependencies {
123-
// Root-only dependencies (not needed by ec-core)
124106
modImplementation "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
125107

126108
// included in fabriclocader 1.15+, kept here for compat on older loaders, I think
@@ -138,10 +120,9 @@ dependencies {
138120
// mod compatibility
139121
modCompileOnly "maven.modrinth:vanish:${project.vanish_version}"
140122

141-
// Subprojects
142123
subprojects.each {
143124
implementation project(path: ":${it.name}", configuration: "namedElements")
144-
include project("${it.name}:") // nest within distribution
125+
include project("${it.name}:")
145126
}
146127
}
147128

@@ -155,37 +136,26 @@ tasks.withType(JavaCompile).configureEach {
155136
it.options.release.set(21)
156137
}
157138

158-
//jar {
159-
// from("LICENSE") {
160-
// rename { "${it}_${project.archivesBaseName}"}
161-
// }
162-
//}
163-
164-
// Define how packages are published
165139
publishing {
166-
// Declare all publications
167140
publications {
168141
mavenJava(MavenPublication) {
169142
artifactId = project.mod_id
170143
groupId = project.maven_group
171144
version = project.version
172-
// Main
173145
artifact(remapJar) { builtBy remapJar }
174-
// Sources
175146
artifact(sourcesJar) {
176147
builtBy remapSourcesJar
177148
}
178149
}
179150
}
180151
// Add repositories to publish to
181152
repositories {
182-
// GitHub Packages (https://pkg.github.com)
183153
mavenLocal {
184154

185155
}
186156
maven {
187157
name 'GitHub'
188-
url "https://maven.pkg.github.com/${project.github_repo}"
158+
url "https://maven.pkg.github.com/${project.gh_owner}/project.gh_repo"
189159
credentials {
190160
username = getenv('GITHUB_ACTOR')
191161
password = getenv('GITHUB_TOKEN')
@@ -194,165 +164,93 @@ publishing {
194164
}
195165
}
196166

197-
198-
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
199-
import com.modrinth.minotaur.TaskModrinthUpload
200-
import com.modrinth.minotaur.request.VersionType
201-
import io.github.themrmilchmann.gradle.publish.curseforge.ChangelogFormat
202-
import io.github.themrmilchmann.gradle.publish.curseforge.GameVersion
203-
import io.github.themrmilchmann.gradle.publish.curseforge.ReleaseType
204-
205-
modrinth {
206-
token = getenv("MODRINTH")
207-
// An environment property called MODRINTH that is your token, set via Gradle CLI, GitHub Actions, Idea Run Configuration, or other
208-
projectId = project.modrinth_project_id
209-
versionNumber = (String) project.version // Will fail if Modrinth has this version already
210-
versionType = project.version.contains('alpha') ? VersionType.ALPHA.toString()
211-
: project.version.contains('beta') ? VersionType.BETA.toString()
212-
: VersionType.RELEASE.toString()
213-
214-
// On fabric with loom, use 'remapJar' instead of 'jar'
215-
uploadFile = remapJar
216-
217-
// This is the java jar task. If it can't find the jar, try 'jar.outputs.getFiles().asPath' in place of 'jar'
218-
gameVersions = List.of(project.mr_game_versions.split(','))
219-
changelog = readLatestChangelogSection()
220-
loaders = ['fabric']
221-
222-
debugMode = false
223-
project.version
224-
dependencies {
225-
if (project.mr_relations_required?.trim()) project.mr_relations_required.split(',').each { required.project(it.trim()) }
226-
if (project.mr_relations_optional?.trim()) project.mr_relations_optional.split(',').each { optional.project(it.trim()) }
227-
if (project.mr_relations_embedded?.trim()) project.mr_relations_embedded.split(',').each { embedded.project(it.trim()) }
228-
if (project.mr_relations_incompatible?.trim()) project.mr_relations_incompatible.split(',').each { incompatible.project(it.trim()) }
167+
// ModPublisher Configuration
168+
publisher {
169+
apiKeys {
170+
modrinth getenv("MODRINTH")
171+
curseforge getenv("CURSEFORGE")
172+
github getenv("GITHUB")
229173
}
230-
}
231174

175+
setDebug(false)
232176

233-
//type:
234-
tasks.register("publishModrinth", TaskModrinthUpload) { // Make sure it runs after build!
235-
description 'Uploads all Modrinth projects'
236-
group 'upload'
177+
setCurseID(project.cf_project_id)
178+
setModrinthID(project.modrinth_project_id)
237179

238-
onlyIf {
239-
// Only attempt to run this task if the MODRINTH variable is set in .env, otherwise SKIP it
240-
env.containsKey("MODRINTH")
241-
}
242-
}
180+
setVersionType(project.version.contains('alpha') ? 'alpha'
181+
: project.version.contains('beta') ? 'beta'
182+
: 'release')
243183

244-
curseforge {
245-
apiToken = getenv("CURSEFORGE")
184+
setChangelog(readLatestChangelogSection())
185+
setProjectVersion(project.version as String)
186+
setDisplayName(project.version as String)
246187

247-
publications {
248-
register("main") {
249-
projectId = project.cf_project_id
188+
setGameVersions(project.game_versions.split(',').collect { it.trim() })
250189

251-
// Convert game versions from comma-separated string to GameVersion objects
252-
project.cf_game_versions.split(',').each { version ->
253-
gameVersions.add(new GameVersion("minecraft-java-edition", version.trim()))
254-
}
190+
setLoaders("fabric")
191+
setCurseEnvironment("both")
255192

256-
artifacts.register("main") {
257-
displayName = "${project.version}"
258-
259-
// Convert release type to enum
260-
releaseType = project.version.contains('alpha') ? ReleaseType.ALPHA
261-
: project.version.contains('beta') ? ReleaseType.BETA
262-
: ReleaseType.RELEASE
263-
264-
// Set up changelog (pointing to GitHub releases instead of inline text)
265-
changelog {
266-
format = ChangelogFormat.TEXT
267-
content = "For a list of changes, please refer to https://github.com/${project.github_repo}/releases/tag/${project.version}"
268-
}
269-
270-
from(remapJar)
271-
272-
// Convert relations configuration
273-
relations {
274-
if (project.cf_relations_required) {
275-
project.cf_relations_required.split(',').each { dep ->
276-
requiredDependency(dep.trim())
277-
}
278-
}
279-
if (project.cf_relations_optional) {
280-
project.cf_relations_optional.split(',').each { dep ->
281-
optionalDependency(dep.trim())
282-
}
283-
}
284-
if (project.cf_relations_embedded) {
285-
project.cf_relations_embedded.split(',').each { dep ->
286-
embeddedLibrary(dep.trim())
287-
}
288-
}
289-
if (project.cf_relations_tools) {
290-
project.cf_relations_tools.split(',').each { dep ->
291-
tool(dep.trim())
292-
}
293-
}
294-
if (project.cf_relations_incompatible) {
295-
project.cf_relations_incompatible.split(',').each { dep ->
296-
incompatible(dep.trim())
297-
}
298-
}
299-
}
300-
}
193+
setArtifact(remapJar)
194+
setJavaVersions([JavaVersion.VERSION_21])
301195

302-
// Add additional artifacts from subprojects
303-
subprojects.eachWithIndex { subproject, index ->
304-
artifacts.register("subproject${index}") {
305-
from(subproject.remapJar)
306-
displayName = "${subproject.name} - ${project.version}"
307-
releaseType = project.version.contains('alpha') ? ReleaseType.ALPHA
308-
: project.version.contains('beta') ? ReleaseType.BETA
309-
: ReleaseType.RELEASE
310-
}
311-
}
312-
}
196+
// Add subproject artifacts as additional files
197+
subprojects.each { subproject ->
198+
addAdditionalFile(subproject.remapJar)
313199
}
314-
}
315200

316-
tasks.register("publishCurseForge") {
317-
description 'Uploads to CurseForge'
318-
group 'upload'
319-
320-
dependsOn 'publishMainPublicationToCurseForge'
321-
322-
onlyIf {
323-
env.containsKey("CURSEFORGE")
201+
github {
202+
repo = "${project.gh_owner}/${project.gh_repo}"
203+
tag = project.version as String
204+
target = "1.21.x"
324205
}
325-
}
326206

327-
tasks.register("publishGithubRelease", GithubReleaseTask) {
328-
description 'Creates a GitHub Release for the project'
329-
group 'upload'
207+
modrinthDepends {
208+
if (project.hasProperty('mr_relations_required') && project.mr_relations_required?.trim()) {
209+
project.mr_relations_required.split(',').each { dep ->
210+
required dep.trim()
211+
}
212+
}
213+
if (project.hasProperty('mr_relations_optional') && project.mr_relations_optional?.trim()) {
214+
project.mr_relations_optional.split(',').each { dep ->
215+
optional dep.trim()
216+
}
217+
}
218+
if (project.hasProperty('mr_relations_embedded') && project.mr_relations_embedded?.trim()) {
219+
project.mr_relations_embedded.split(',').each { dep ->
220+
embedded dep.trim()
221+
}
222+
}
223+
if (project.hasProperty('mr_relations_incompatible') && project.mr_relations_incompatible?.trim()) {
224+
project.mr_relations_incompatible.split(',').each { dep ->
225+
incompatible dep.trim()
226+
}
227+
}
228+
}
330229

331-
onlyIf {
332-
env.containsKey("GITHUB")
230+
curseDepends {
231+
if (project.hasProperty('cf_relations_required') && project.cf_relations_required?.trim()) {
232+
project.cf_relations_required.split(',').each { dep ->
233+
required dep.trim()
234+
}
235+
}
236+
if (project.hasProperty('cf_relations_optional') && project.cf_relations_optional?.trim()) {
237+
project.cf_relations_optional.split(',').each { dep ->
238+
optional dep.trim()
239+
}
240+
}
241+
if (project.hasProperty('cf_relations_embedded') && project.cf_relations_embedded?.trim()) {
242+
project.cf_relations_embedded.split(',').each { dep ->
243+
embedded dep.trim()
244+
}
245+
}
246+
if (project.hasProperty('cf_relations_incompatible') && project.cf_relations_incompatible?.trim()) {
247+
project.cf_relations_incompatible.split(',').each { dep ->
248+
incompatible dep.trim()
249+
}
250+
}
333251
}
334252
}
335-
githubRelease {
336-
token = getenv("GITHUB") // This is your personal access token with Repo permissions
337-
// You get this from your user settings > developer settings > Personal Access Tokens
338-
owner = project.gh_owner // default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
339-
repo = project.gh_repo // by default this is set to your project name
340-
tagName = project.version as String // by default this is set to "v${project.version}"
341-
targetCommitish = "1.21.x" // by default this is set to "master"
342-
releaseName = project.version as String // Release title, by default this is the same as the tagName
343-
body = readLatestChangelogSection() // by default this is empty
344-
draft = false // by default this is false
345-
prerelease = false // by default this is false
346-
releaseAssets base.libsDirectory
347-
.getAsFileTree()
348-
.matching((PatternFilterable pattern) -> pattern.include("**/*${project.version}.jar"))
349-
//jar.outputs.getFiles().asPath//
350-
overwrite = false // by default false; if set to true, will delete an existing release with the same tag and name
351-
dryRun = false // by default false; you can use this to see what actions would be taken without making a release
352-
apiEndpoint = "https://api.github.com" // should only change for github enterprise users
353-
client // This is the okhttp client used for http requests
354-
allowUploadToExisting = false
355-
}
253+
356254

357255
generatePomFileForMavenJavaPublication {}
358256

0 commit comments

Comments
 (0)