|
| 1 | +plugins { |
| 2 | + id 'java-library' |
| 3 | + id 'maven-publish' |
| 4 | + id 'net.neoforged.gradle.userdev' version '7.0.184' |
| 5 | +} |
| 6 | + |
| 7 | +tasks.named('wrapper', Wrapper).configure { |
| 8 | + // Define wrapper values here so as to not have to always do so when updating gradlew.properties. |
| 9 | + // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with |
| 10 | + // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased |
| 11 | + // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards. |
| 12 | + // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`) |
| 13 | + distributionType = Wrapper.DistributionType.BIN |
| 14 | +} |
| 15 | + |
| 16 | +def getVersionFromFile() { |
| 17 | + def versionFile = file('../version') |
| 18 | + if (versionFile.exists()) { |
| 19 | + return versionFile.text.trim() |
| 20 | + } else { |
| 21 | + throw new GradleException("Version file not found: ${versionFile.absolutePath}") |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +version = getVersionFromFile() |
| 26 | +mod_version = version |
| 27 | +group = mod_group_id |
| 28 | + |
| 29 | +repositories { |
| 30 | + mavenLocal() |
| 31 | + |
| 32 | +// maven { |
| 33 | +// name = 'Kotlin for Forge' |
| 34 | +// url = 'https://thedarkcolour.github.io/KotlinForForge/' |
| 35 | +// content { includeGroup "thedarkcolour" } |
| 36 | +// } |
| 37 | +} |
| 38 | + |
| 39 | +base { |
| 40 | + archivesName = file_name |
| 41 | +} |
| 42 | + |
| 43 | +// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21. |
| 44 | +java.toolchain.languageVersion = JavaLanguageVersion.of(21) |
| 45 | + |
| 46 | +// Enable the Jar-in-Jar system for your mod |
| 47 | +jarJar.enable() |
| 48 | + |
| 49 | +// Default run configurations. |
| 50 | +// These can be tweaked, removed, or duplicated as needed. |
| 51 | +runs { |
| 52 | + // applies to all the run configs below |
| 53 | + configureEach { |
| 54 | + // Recommended logging data for a userdev environment |
| 55 | + // The markers can be added/remove as needed separated by commas. |
| 56 | + // "SCAN": For mods scan. |
| 57 | + // "REGISTRIES": For firing of registry events. |
| 58 | + // "REGISTRYDUMP": For getting the contents of all registries. |
| 59 | + systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 60 | + |
| 61 | + // Recommended logging level for the console |
| 62 | + // You can set various levels here. |
| 63 | + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels |
| 64 | + systemProperty 'forge.logging.console.level', 'debug' |
| 65 | + |
| 66 | + modSource project.sourceSets.main |
| 67 | + } |
| 68 | + |
| 69 | + client { |
| 70 | + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. |
| 71 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 72 | + } |
| 73 | + |
| 74 | + server { |
| 75 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 76 | + argument '--nogui' |
| 77 | + } |
| 78 | + |
| 79 | + // This run config launches GameTestServer and runs all registered gametests, then exits. |
| 80 | + // By default, the server will crash when no gametests are provided. |
| 81 | + // The gametest system is also enabled by default for other run configs under the /test command. |
| 82 | + gameTestServer { |
| 83 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 84 | + } |
| 85 | + |
| 86 | + clientData { |
| 87 | + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it |
| 88 | + // workingDirectory project.file('run-data') |
| 89 | + |
| 90 | + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. |
| 91 | + arguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +// Include resources generated by data generators. |
| 96 | +sourceSets.main.resources { srcDir 'src/generated/resources' } |
| 97 | + |
| 98 | +// Sets up a dependency configuration called 'localRuntime'. |
| 99 | +// This configuration should be used instead of 'runtimeOnly' to declare |
| 100 | +// a dependency that will be present for runtime testing but that is |
| 101 | +// "optional", meaning it will not be pulled by dependents of this mod. |
| 102 | +configurations { |
| 103 | + runtimeClasspath.extendsFrom localRuntime |
| 104 | +} |
| 105 | + |
| 106 | +dependencies { |
| 107 | + // Specify the version of Minecraft to use. |
| 108 | + // Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above. |
| 109 | + // The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version. |
| 110 | + // You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader. |
| 111 | + // And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version. |
| 112 | + // For all intends and purposes: You can treat this dependency as if it is a normal library you would use. |
| 113 | + implementation "net.neoforged:neoforge:${neo_version}" |
| 114 | + |
| 115 | + // Example optional mod dependency with JEI |
| 116 | + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime |
| 117 | + // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" |
| 118 | + // compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}" |
| 119 | + // We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it |
| 120 | + // localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" |
| 121 | + |
| 122 | + implementation 'com.squareup.okhttp3:okhttp:4.12.0' |
| 123 | + implementation 'org.xerial:sqlite-jdbc:3.48.0.0' |
| 124 | +// implementation "thedarkcolour:kotlinforforge:$kff_version" |
| 125 | + |
| 126 | +// jarJar (group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: '[2.0, 2.1)') |
| 127 | +// jarJar (group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk7', version: '[2.0, 2.1)') |
| 128 | +// jarJar (group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '[2.0, 2.1)') |
| 129 | +// jarJar (group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-common', version: '[2.0, 2.1)') |
| 130 | + jarJar (group: 'com.squareup.okhttp3', name: 'okhttp', version: '[4.12, 5.0)') |
| 131 | + jarJar (group: 'com.squareup.okio', name: 'okio-jvm', version: '[3.9, 4.0)') |
| 132 | + jarJar (group: 'org.xerial', name: 'sqlite-jdbc', version: '[3.46, 4.0)') |
| 133 | + |
| 134 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 135 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 136 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 137 | + // implementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 138 | + |
| 139 | + // Example mod dependency using a file as dependency |
| 140 | + // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") |
| 141 | + |
| 142 | + // Example project dependency using a sister or child project: |
| 143 | + // implementation project(":myproject") |
| 144 | + |
| 145 | + // For more info: |
| 146 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 147 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 148 | +} |
| 149 | + |
| 150 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 151 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 152 | +// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. |
| 153 | +// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html |
| 154 | +tasks.withType(ProcessResources).configureEach { |
| 155 | + var replaceProperties = [ |
| 156 | + minecraft_version : minecraft_version, |
| 157 | + minecraft_version_range: minecraft_version_range, |
| 158 | + neo_version : neo_version, |
| 159 | + neo_version_range : neo_version_range, |
| 160 | + loader_version_range : loader_version_range, |
| 161 | + mod_id : mod_id, |
| 162 | + mod_name : mod_name, |
| 163 | + mod_license : mod_license, |
| 164 | + mod_version : mod_version, |
| 165 | + mod_authors : mod_authors, |
| 166 | + mod_description : mod_description |
| 167 | + ] |
| 168 | + inputs.properties replaceProperties |
| 169 | + |
| 170 | + filesMatching(['META-INF/neoforge.mods.toml']) { |
| 171 | + expand replaceProperties |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +// Example configuration to allow publishing using the maven-publish plugin |
| 176 | +publishing { |
| 177 | + publications { |
| 178 | + register('mavenJava', MavenPublication) { |
| 179 | + from components.java |
| 180 | + } |
| 181 | + } |
| 182 | + repositories { |
| 183 | + maven { |
| 184 | + url "file://${project.projectDir}/repo" |
| 185 | + } |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +tasks.withType(JavaCompile).configureEach { |
| 190 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 191 | +} |
| 192 | + |
| 193 | +// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. |
| 194 | +idea { |
| 195 | + module { |
| 196 | + downloadSources = true |
| 197 | + downloadJavadoc = true |
| 198 | + } |
| 199 | +} |
0 commit comments