Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Build Workflow

name: Build with Gradle

on:
pull_request:
workflow_dispatch:
push:

concurrency:
group: ${{ github.head_ref || format('{0}-{1}', github.ref, github.run_number) }}
cancel-in-progress: true

jobs:
build:
name: Build

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 10

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin

- uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
**/loom-cache
**/prebundled-jars
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Chmod Gradle
run: chmod +x ./gradlew

- name: Build
run: ./gradlew build --no-daemon
129 changes: 72 additions & 57 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
@file:Suppress("UnstableApiUsage", "PropertyName")

import cc.polyfrost.gradle.util.noServerRunConfigs
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit which we use to prepare the environment.
// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
// which we use to prepare the environment.
plugins {
kotlin("jvm")
id("cc.polyfrost.multi-version")
Expand Down Expand Up @@ -36,6 +39,7 @@ version = mod_version
// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
// e.g. com.github.<your username> or com.<your domain>
group = "cc.polyfrost"

// Sets the name of the output jar (the one you put in your mods folder and send to other people)
// It outputs all versions of the mod into the `build` directory.
base {
Expand All @@ -44,25 +48,29 @@ base {

// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
loom {
// Removes the server configs from IntelliJ IDEA, since we aren't developing a server mod.
// Removes the server configs from IntelliJ IDEA, leaving only client runs.
// If you're developing a server-side mod, you can remove this line.
noServerRunConfigs()

// Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.cc)
if (project.platform.isLegacyForge) {
launchConfigs.named("client") {
arg("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker")

// This is enabled so OneConfig can read our Mixins and automatically apply them.
property(
"mixin.debug.export",
"true"
) // This is enabled so OneConfig can read our Mixins and automatically apply them.
)
}
}
// Configures the mixins if we are building for forge. (Useful for when we are dealing with cross-platform projects.
// Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
if (project.platform.isForge) {
forge {
mixinConfig("mixins.${mod_id}.json")
}
}
// Configures the name of the mixin "refmap" using an experimental loom api. You can ignore this warning.
// Configures the name of the mixin "refmap" using an experimental loom api.
mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json")
}

Expand All @@ -78,14 +86,15 @@ sourceSets {
}
}

// Adds the Polyfrost maven repository so we can get the libraries necessary to develop the mod.
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
repositories {
maven("https://repo.polyfrost.cc/releases")
}

// Configures the libraries/dependencies for your mod.
dependencies {
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.0-alpha+") // Adds the OneConfig library, so we can develop with it.
// Adds the OneConfig library, so we can develop with it.
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.0-alpha+")

// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (platform.isLegacyForge) {
Expand All @@ -94,48 +103,52 @@ dependencies {
}
}

// Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces the mod id, name and version with the ones in `gradle.properties`
tasks.processResources {
inputs.property("id", mod_id)
inputs.property("name", mod_name)
val java = if (project.platform.mcMinor >= 18) {
17 // If we are playing on version 1.18, set the java version to 17
} else {
// Else if we are playing on version 1.17, use java 16.
if (project.platform.mcMinor == 17) 16 else 8 // For all previous versions, java version 8 is okay.
}
val compatLevel = "JAVA_${java}"
inputs.property("java", java)
inputs.property("java_level", compatLevel)
inputs.property("version", mod_version)
inputs.property("mcVersionStr", project.platform.mcVersionStr)
filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) {
expand(
mapOf(
"id" to mod_id,
"name" to mod_name,
"java" to java,
"java_level" to compatLevel,
"version" to mod_version,
"mcVersionStr" to project.platform.mcVersionStr
tasks {
// Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces
// the mod id, name and version with the ones in `gradle.properties`
processResources {
inputs.property("id", mod_id)
inputs.property("name", mod_name)
val java = if (project.platform.mcMinor >= 18) {
17 // If we are playing on version 1.18, set the java version to 17
} else {
// Else if we are playing on version 1.17, use java 16.
if (project.platform.mcMinor == 17)
16
else
8 // For all previous versions, we **need** java 8 (for Forge support).
}
val compatLevel = "JAVA_${java}"
inputs.property("java", java)
inputs.property("java_level", compatLevel)
inputs.property("version", mod_version)
inputs.property("mcVersionStr", project.platform.mcVersionStr)
filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) {
expand(
mapOf(
"id" to mod_id,
"name" to mod_name,
"java" to java,
"java_level" to compatLevel,
"version" to mod_version,
"mcVersionStr" to project.platform.mcVersionStr
)
)
)
}
filesMatching("fabric.mod.json") {
expand(
mapOf(
"id" to mod_id,
"name" to mod_name,
"java" to java,
"java_level" to compatLevel,
"version" to mod_version,
"mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x"
}
filesMatching("fabric.mod.json") {
expand(
mapOf(
"id" to mod_id,
"name" to mod_name,
"java" to java,
"java_level" to compatLevel,
"version" to mod_version,
"mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x"
)
)
)
}
}
}

tasks {
// Configures the resources to include if we are building for forge or fabric.
withType(Jar::class.java) {
if (project.platform.isFabric) {
Expand All @@ -149,27 +162,29 @@ tasks {
}
}
}
// Configures our shadow/shade configuration, so we can include the OneConfig launch wrapper with our mod.

// Configures our shadow/shade configuration, so we can
// include some dependencies within our mod jar file.
named<ShadowJar>("shadowJar") {
archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix.
configurations = listOf(shade)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

remapJar {
input.set(shadowJar.get().archiveFile)
archiveClassifier.set("")
}
// Sets the jar manifest attributes.

jar {
manifest {
attributes(
mapOf(
"ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine.
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so.
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
"MixinConfigs" to "mixin.${mod_id}.json", // We want to use our mixin configuration, so we specify it here.
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
)
// Sets the jar manifest attributes.
if (platform.isLegacyForge) {
manifest.attributes += mapOf(
"ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine.
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so.
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
"MixinConfigs" to "mixin.${mod_id}.json", // We want to use our mixin configuration, so we specify it here.
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
)
}
dependsOn(shadowJar)
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod_name=ExampleMod
# Sets the id of your mod that mod loaders use to recognize it.
mod_id=examplemod
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
mod_version=1.0.0
# Sets the name of the jar file that you put in your mods folder.
# Sets the name of the jar file that you put in your 'mods' folder.
mod_archives_name=ExampleMod

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
loom.platform=forge
polyfrost.defaults.loom=1
org.gradle.daemon=true
org.gradle.parallel=true
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

networkTimeout=30000
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@file:Suppress("PropertyName")

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://repo.polyfrost.cc/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit
}
plugins {
val pgtVersion = "0.1.27" // Sets the default versions for Polyfrost Gradle Toolkit
val pgtVersion = "0.1.28" // Sets the default versions for Polyfrost Gradle Toolkit
id("cc.polyfrost.multi-version.root") version pgtVersion
}
}
Expand All @@ -26,4 +28,4 @@ listOf(
projectDir = file("versions/$version")
buildFileName = "../../build.gradle.kts"
}
}
}