|
| 1 | +/* |
| 2 | + * This file is derived from the NeoForged MDK at https://github.com/NeoForgeMDKs/MDK-1.21-ModDevGradle. |
| 3 | + * The license is reproduced below. |
| 4 | + * |
| 5 | + * MIT License |
| 6 | + * |
| 7 | + * Copyright (c) 2023 NeoForged project |
| 8 | + * |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in all |
| 17 | + * copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | + * SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +plugins { |
| 29 | + id 'java-library' |
| 30 | + id 'maven-publish' |
| 31 | + id 'net.neoforged.moddev' version '2.0.88' |
| 32 | + id 'idea' |
| 33 | +} |
| 34 | + |
| 35 | +tasks.named('wrapper', Wrapper).configure { |
| 36 | + // Define wrapper values here so as to not have to always do so when updating gradlew.properties. |
| 37 | + // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with |
| 38 | + // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased |
| 39 | + // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards. |
| 40 | + // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`) |
| 41 | + distributionType = Wrapper.DistributionType.BIN |
| 42 | +} |
| 43 | + |
| 44 | +version = mod_version |
| 45 | +group = mod_group_id |
| 46 | + |
| 47 | +repositories { |
| 48 | + mavenLocal() |
| 49 | + mavenCentral() |
| 50 | + maven { |
| 51 | + name = "modrinth" |
| 52 | + url = "https://api.modrinth.com/maven" |
| 53 | + } |
| 54 | + maven { |
| 55 | + name = "TerraformersMC" |
| 56 | + url = "https://maven.terraformersmc.com/" |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +base { |
| 61 | + archivesName = mod_id |
| 62 | +} |
| 63 | + |
| 64 | +java { |
| 65 | + // Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21. |
| 66 | + toolchain.languageVersion = JavaLanguageVersion.of(21) |
| 67 | + withSourcesJar() |
| 68 | +} |
| 69 | + |
| 70 | +neoForge { |
| 71 | + // Specify the version of NeoForge to use. |
| 72 | + version = project.neo_version |
| 73 | + |
| 74 | + parchment { |
| 75 | + mappingsVersion = project.parchment_mappings_version |
| 76 | + minecraftVersion = project.parchment_minecraft_version |
| 77 | + } |
| 78 | + |
| 79 | + validateAccessTransformers = true |
| 80 | + |
| 81 | + accessTransformers { |
| 82 | + file('src/main/resources/META-INF/accesstransformer.cfg') |
| 83 | + } |
| 84 | + |
| 85 | + // Default run configurations. |
| 86 | + // These can be tweaked, removed, or duplicated as needed. |
| 87 | + runs { |
| 88 | + client { |
| 89 | + client() |
| 90 | + |
| 91 | + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. |
| 92 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 93 | + } |
| 94 | + |
| 95 | + server { |
| 96 | + server() |
| 97 | + programArgument '--nogui' |
| 98 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 99 | + } |
| 100 | + |
| 101 | + // This run config launches GameTestServer and runs all registered gametests, then exits. |
| 102 | + // By default, the server will crash when no gametests are provided. |
| 103 | + // The gametest system is also enabled by default for other run configs under the /test command. |
| 104 | + gameTestServer { |
| 105 | + type = "gameTestServer" |
| 106 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 107 | + } |
| 108 | + |
| 109 | + data { |
| 110 | + data() |
| 111 | + |
| 112 | + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it |
| 113 | + // gameDirectory = project.file('run-data') |
| 114 | + |
| 115 | + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. |
| 116 | + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() |
| 117 | + } |
| 118 | + |
| 119 | + // applies to all the run configs above |
| 120 | + configureEach { |
| 121 | + // Recommended logging data for a userdev environment |
| 122 | + // The markers can be added/remove as needed separated by commas. |
| 123 | + // "SCAN": For mods scan. |
| 124 | + // "REGISTRIES": For firing of registry events. |
| 125 | + // "REGISTRYDUMP": For getting the contents of all registries. |
| 126 | + systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 127 | + |
| 128 | + // Recommended logging level for the console |
| 129 | + // You can set various levels here. |
| 130 | + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels |
| 131 | + logLevel = org.slf4j.event.Level.DEBUG |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + mods { |
| 136 | + // define mod <-> source bindings |
| 137 | + // these are used to tell the game which sources are for which mod |
| 138 | + // mostly optional in a single mod project |
| 139 | + // but multi mod projects should define one per mod |
| 140 | + "${mod_id}" { |
| 141 | + sourceSet(sourceSets.main) |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +// Include resources generated by data generators. |
| 147 | +sourceSets.main.resources { srcDir 'src/generated/resources' } |
| 148 | + |
| 149 | +// Sets up a dependency configuration called 'localRuntime'. |
| 150 | +// This configuration should be used instead of 'runtimeOnly' to declare |
| 151 | +// a dependency that will be present for runtime testing but that is |
| 152 | +// "optional", meaning it will not be pulled by dependents of this mod. |
| 153 | +configurations { |
| 154 | + runtimeClasspath.extendsFrom localRuntime |
| 155 | +} |
| 156 | + |
| 157 | +dependencies { |
| 158 | + // Example optional mod dependency with JEI |
| 159 | + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime |
| 160 | + // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" |
| 161 | + // compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}" |
| 162 | + // We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it |
| 163 | + // localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" |
| 164 | + |
| 165 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 166 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 167 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 168 | + // implementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 169 | + |
| 170 | + // Example mod dependency using a file as dependency |
| 171 | + // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") |
| 172 | + |
| 173 | + // Example project dependency using a sister or child project: |
| 174 | + // implementation project(":myproject") |
| 175 | + |
| 176 | + // For more info: |
| 177 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 178 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 179 | + |
| 180 | + compileOnly "org.appliedenergistics:appliedenergistics2:${project.ae2_version}:api" |
| 181 | + implementation "org.appliedenergistics:appliedenergistics2:${project.ae2_version}" |
| 182 | + |
| 183 | + localRuntime "dev.emi:emi-neoforge:${project.emi_version}" |
| 184 | + localRuntime "maven.modrinth:jade:${project.jade_version}" |
| 185 | +} |
| 186 | + |
| 187 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 188 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 189 | +var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) { |
| 190 | + var replaceProperties = [ |
| 191 | + minecraft_version : minecraft_version, |
| 192 | + minecraft_version_range: minecraft_version_range, |
| 193 | + neo_version : neo_version, |
| 194 | + neo_version_range : neo_version_range, |
| 195 | + loader_version_range : loader_version_range, |
| 196 | + mod_id : mod_id, |
| 197 | + mod_name : mod_name, |
| 198 | + mod_license : mod_license, |
| 199 | + mod_version : mod_version, |
| 200 | + mod_authors : mod_authors, |
| 201 | + mod_description : mod_description |
| 202 | + ] |
| 203 | + inputs.properties replaceProperties |
| 204 | + expand replaceProperties |
| 205 | + from "src/main/templates" |
| 206 | + into "build/generated/sources/modMetadata" |
| 207 | +} |
| 208 | +// Include the output of "generateModMetadata" as an input directory for the build |
| 209 | +// this works with both building through Gradle and the IDE. |
| 210 | +sourceSets.main.resources.srcDir generateModMetadata |
| 211 | +// To avoid having to run "generateModMetadata" manually, make it run on every project reload |
| 212 | +neoForge.ideSyncTask generateModMetadata |
| 213 | + |
| 214 | +// Example configuration to allow publishing using the maven-publish plugin |
| 215 | +publishing { |
| 216 | + publications { |
| 217 | + register('mavenJava', MavenPublication) { |
| 218 | + from components.java |
| 219 | + } |
| 220 | + } |
| 221 | + repositories { |
| 222 | + maven { |
| 223 | + url "file://${project.projectDir}/repo" |
| 224 | + } |
| 225 | + } |
| 226 | +} |
| 227 | + |
| 228 | +tasks.withType(JavaCompile).configureEach { |
| 229 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 230 | +} |
| 231 | + |
| 232 | +// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. |
| 233 | +idea { |
| 234 | + module { |
| 235 | + downloadSources = true |
| 236 | + downloadJavadoc = true |
| 237 | + } |
| 238 | +} |
0 commit comments