Skip to content

Commit

Permalink
Setup publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongmario committed Sep 3, 2024
1 parent 35f9bab commit b4e84fe
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,5 @@ idea.project.settings {
}
}

apply from: 'gradle/scripts/publishing.gradle'
apply from: 'gradle/scripts/extra.gradle'
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ maven_url =

# Publishing
# release_type can only be: release, beta or alpha (applies to CurseForge / Modrinth)
release_type = release
release_type = beta
publish_with_changelog = ${{ it.file('CHANGELOG.md').exists() }}

# Publishing to CurseForge (Provide secret: CURSEFORGE_TOKEN)
# To configure dependencies, head to publishing.gradle's curseforge block
publish_to_curseforge = false
publish_to_curseforge = true
# CurseForge project ID must be the numerical ID and not the slug
curseforge_project_id =
curseforge_project_id = 692142
curseforge_debug = false

# Publishing to Modrinth (Provide secret: MODRINTH_TOKEN), the token must have the `CREATE_VERSION` and `PROJECT_WRITE` permissions
# To configure dependencies, head to publishing.gradle's modrinth block
publish_to_modrinth = false
modrinth_project_id =
publish_to_modrinth = true
modrinth_project_id = rWzXKfPV
# Allows gradle to publish updated READMEs to the project body (via the modrinthSyncBody task)
modrinth_sync_readme = false
modrinth_debug = false
Expand Down
107 changes: 107 additions & 0 deletions gradle/scripts/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apply from: 'gradle/scripts/helpers.gradle'

setDefaultProperty('publish_to_maven', true, false)
setDefaultProperty('publish_to_curseforge', true, false)
setDefaultProperty('publish_to_modrinth', true, false)

if (propertyBool('publish_to_maven')) {
assertProperty('maven_name')
assertProperty('maven_url')
publishing {
repositories {
maven {
name propertyString('maven_name').replaceAll("\\s", "")
url propertyString('maven_url')
credentials(PasswordCredentials)
}
}
publications {
mavenJava(MavenPublication) {
from components.java // Publish with standard artifacts
setGroupId(propertyString('root_package'))// Publish with root package as maven group
setArtifactId(propertyString('mod_id')) // Publish artifacts with mod id as the artifact id

// Custom artifact:
// If you want to publish a different artifact to the one outputted when building normally
// Create a different gradle task (Jar task), in extra.gradle
// Remove the 'from components.java' line above
// Add this line (change the task name):
// artifacts task_name
}
}
}
}

// Documentation here: https://github.com/matthewprenger/CurseGradle/wiki/
if (propertyBool('publish_to_curseforge')) {
apply plugin: 'com.matthewprenger.cursegradle'
assertProperty('curseforge_project_id')
assertProperty('release_type')
setDefaultProperty('curseforge_debug', false, false)
curseforge {
apiKey = System.getenv('CURSEFORGE_TOKEN') == null ? "" : System.getenv('CURSEFORGE_TOKEN')
// noinspection GroovyAssignabilityCheck
project {
id = propertyString('curseforge_project_id')
addGameVersion 'Java 8'
addGameVersion 'Forge'
addGameVersion '1.12.2'
releaseType = propertyString('release_type')
if (!propertyBool('publish_with_changelog')) {
changelog = parserChangelog()
changelogType = 'markdown'
}
mainArtifact tasks.reobfJar, {
displayName = "${propertyString('mod_name')} ${propertyString('mod_version')}"
if (propertyBool('use_mixins')) {
relations {
requiredDependency 'mixin-booter'
}
}
if (propertyBool('use_asset_mover')) {
relations {
requiredDependency 'assetmover'
}
}
}
options {
debug = propertyBool('curseforge_debug')
}
}
}
}

// Documentation here: https://github.com/modrinth/minotaur
if (propertyBool('publish_to_modrinth')) {
apply plugin: 'com.modrinth.minotaur'
assertProperty('modrinth_project_id')
assertProperty('release_type')
setDefaultProperty('modrinth_debug', false, false)
modrinth {
token = System.getenv('MODRINTH_TOKEN') ? "" : System.getenv('MODRINTH_TOKEN')
projectId = propertyString('modrinth_project_id')
versionNumber = propertyString('mod_version')
versionType = propertyString('release_type')
uploadFile = tasks.reobfJar
gameVersions = ['1.12.2']
loaders = ['forge']
debugMode = propertyBool('modrinth_debug')
if (propertyBool('use_mixins') || propertyBool('use_asset_mover')) {
dependencies {
if (propertyBool('use_mixins')) {
required.project 'mixinbooter'
}
if (propertyBool('use_asset_mover')) {
required.project 'assetmover'
}
}
}
if (!propertyBool('publish_with_changelog')) {
changelog = parserChangelog()
}
if (propertyBool('modrinth_sync_readme')) {
syncBodyFrom = file('README.md').text
tasks.modrinth.dependsOn(tasks.modrinthSyncBody)
}
}
}

0 comments on commit b4e84fe

Please sign in to comment.