Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slurp mod version from json to avoid issues in IDE #113

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

// Obtains mod version. change file reference if your fabric.mod.json is located elsewhere
import groovy.json.JsonSlurper
version = new JsonSlurper().parse(file('src/main/resources/fabric.mod.json')).version

// You can use logger.lifecycle to print out messages like System.out; double-quote strings convert
// ${statement} templates to statement values, such as method calls, while single-quote strings don't.
// getXxx() calls can be simplified to xxx, like project.getGradle().getGradleVersion() is project.gradle.gradleVersion.
// Since the buildscript is provided with a project, you can call project methods without qualification if there is no
// ambiguity, such as file() call to retrieve version is project.file(), and gradle is project.getGradle()
logger.lifecycle "Setting up ${archivesBaseName} ${version} with Gradle ${gradle.gradleVersion}"

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand All @@ -26,17 +36,6 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

tasks.withType(JavaCompile).configureEach {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.6

# Mod Properties
mod_version = 1.0.0
# edit your mod version in fabric.mod.json
maven_group = com.example
archives_base_name = fabric-example-mod

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "modid",
"version": "${version}",
"version": "1.0.0",

"name": "Example Mod",
"description": "This is an example description! Tell everyone what your mod is about!",
Expand Down