|
| 1 | +plugins { |
| 2 | + id 'idea' |
| 3 | + id 'java-library' |
| 4 | + id 'maven-publish' |
| 5 | + id 'net.neoforged.moddev.legacyforge' version '2.0.141' |
| 6 | +} |
| 7 | + |
| 8 | +tasks.named('wrapper', Wrapper).configure { |
| 9 | + // Define wrapper values here so as to not have to always do so when updating gradlew.properties. |
| 10 | + // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with |
| 11 | + // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased |
| 12 | + // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards. |
| 13 | + // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`) |
| 14 | + distributionType = Wrapper.DistributionType.BIN |
| 15 | +} |
| 16 | + |
| 17 | +version = mod_version |
| 18 | +group = mod_group_id |
| 19 | + |
| 20 | +repositories { |
| 21 | + mavenLocal() |
| 22 | + flatDir { |
| 23 | + dirs 'libs' |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +base { |
| 28 | + archivesName = mod_id |
| 29 | +} |
| 30 | + |
| 31 | +// Mojang ships Java 17 to end users in 1.20.1, so mods should target Java 17. |
| 32 | +java.toolchain.languageVersion = JavaLanguageVersion.of(17) |
| 33 | + |
| 34 | +legacyForge { |
| 35 | + // Specify the version of MinecraftForge to use. |
| 36 | + version = project.minecraft_version + '-' + project.forge_version |
| 37 | + |
| 38 | + parchment { |
| 39 | + mappingsVersion = project.parchment_mappings_version |
| 40 | + minecraftVersion = project.parchment_minecraft_version |
| 41 | + } |
| 42 | + |
| 43 | + // This line is optional. Access Transformers are automatically detected |
| 44 | + // accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg') |
| 45 | + |
| 46 | + // Default run configurations. |
| 47 | + // These can be tweaked, removed, or duplicated as needed. |
| 48 | + runs { |
| 49 | + client { |
| 50 | + client() |
| 51 | + |
| 52 | + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. |
| 53 | + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id |
| 54 | + } |
| 55 | + |
| 56 | + server { |
| 57 | + server() |
| 58 | + programArgument '--nogui' |
| 59 | + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id |
| 60 | + } |
| 61 | + |
| 62 | + // This run config launches GameTestServer and runs all registered gametests, then exits. |
| 63 | + // By default, the server will crash when no gametests are provided. |
| 64 | + // The gametest system is also enabled by default for other run configs under the /test command. |
| 65 | + gameTestServer { |
| 66 | + type = "gameTestServer" |
| 67 | + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id |
| 68 | + } |
| 69 | + |
| 70 | + data { |
| 71 | + data() |
| 72 | + |
| 73 | + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it |
| 74 | + // gameDirectory = project.file('run-data') |
| 75 | + |
| 76 | + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. |
| 77 | + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() |
| 78 | + } |
| 79 | + |
| 80 | + // applies to all the run configs above |
| 81 | + configureEach { |
| 82 | + // Recommended logging data for a userdev environment |
| 83 | + // The markers can be added/remove as needed separated by commas. |
| 84 | + // "SCAN": For mods scan. |
| 85 | + // "REGISTRIES": For firing of registry events. |
| 86 | + // "REGISTRYDUMP": For getting the contents of all registries. |
| 87 | + systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 88 | + |
| 89 | + // Recommended logging level for the console |
| 90 | + // You can set various levels here. |
| 91 | + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels |
| 92 | + logLevel = org.slf4j.event.Level.DEBUG |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + mods { |
| 97 | + // define mod <-> source bindings |
| 98 | + // these are used to tell the game which sources are for which mod |
| 99 | + // mostly optional in a single mod project |
| 100 | + // but multi mod projects should define one per mod |
| 101 | + "${mod_id}" { |
| 102 | + sourceSet(sourceSets.main) |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +// Include resources generated by data generators. |
| 108 | +sourceSets.main.resources { srcDir 'src/generated/resources' } |
| 109 | + |
| 110 | +// Sets up a dependency configuration called 'localRuntime' and a deobfuscating one called 'modLocalRuntime' |
| 111 | +// These configurations should be used instead of 'runtimeOnly' to declare |
| 112 | +// a dependency that will be present for runtime testing but that is |
| 113 | +// "optional", meaning it will not be pulled by dependents of this mod. |
| 114 | +configurations { |
| 115 | + runtimeClasspath.extendsFrom localRuntime |
| 116 | +} |
| 117 | +obfuscation { |
| 118 | + createRemappingConfiguration(configurations.localRuntime) |
| 119 | +} |
| 120 | + |
| 121 | +dependencies { |
| 122 | + // If you wish to declare dependencies against mods, make sure to use the 'mod*' configurations so that they're remapped. |
| 123 | + // See https://github.com/neoforged/ModDevGradle/blob/main/LEGACY.md#remapping-mod-dependencies for more information. |
| 124 | + |
| 125 | + // Example optional mod dependency with JEI |
| 126 | + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime |
| 127 | + // modCompileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" |
| 128 | + // modCompileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}" |
| 129 | + // We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it |
| 130 | + // modLocalRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" |
| 131 | + |
| 132 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 133 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 134 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 135 | + // modImplementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 136 | + |
| 137 | + // Example mod dependency using a file as dependency |
| 138 | + // modImplementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") |
| 139 | + |
| 140 | + // Example project dependency using a sister or child project: |
| 141 | + // modImplementation project(":myproject") |
| 142 | + |
| 143 | + // For more info: |
| 144 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 145 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 146 | + |
| 147 | + modImplementation("blank:MesdagPortLib-${portlib_version}:universal") |
| 148 | +} |
| 149 | + |
| 150 | +// Uncomment the lines below if you wish to configure mixin. The mixin file should be named modid.mixins.json. |
| 151 | + |
| 152 | +mixin { |
| 153 | + add sourceSets.main, "${mod_id}.refmap.json" |
| 154 | + config "${mod_id}.mixins.json" |
| 155 | +} |
| 156 | + |
| 157 | +dependencies { |
| 158 | + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' |
| 159 | +} |
| 160 | + |
| 161 | +jar { |
| 162 | + manifest.attributes([ |
| 163 | + "MixinConfigs": "${mod_id}.mixins.json" |
| 164 | + ]) |
| 165 | +} |
| 166 | + |
| 167 | + |
| 168 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 169 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 170 | +tasks.withType(ProcessResources).configureEach { |
| 171 | + var replaceProperties = [ |
| 172 | + minecraft_version : minecraft_version, |
| 173 | + minecraft_version_range: minecraft_version_range, |
| 174 | + forge_version : forge_version, |
| 175 | + forge_version_range : forge_version_range, |
| 176 | + loader_version_range : loader_version_range, |
| 177 | + mod_id : mod_id, |
| 178 | + mod_name : mod_name, |
| 179 | + mod_license : mod_license, |
| 180 | + mod_version : mod_version, |
| 181 | + mod_authors : mod_authors, |
| 182 | + mod_description : mod_description |
| 183 | + ] |
| 184 | + inputs.properties replaceProperties |
| 185 | + |
| 186 | + filesMatching(['META-INF/mods.toml']) { |
| 187 | + expand replaceProperties |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +// Example configuration to allow publishing using the maven-publish plugin |
| 192 | +publishing { |
| 193 | + publications { |
| 194 | + register('mavenJava', MavenPublication) { |
| 195 | + from components.java |
| 196 | + } |
| 197 | + } |
| 198 | + repositories { |
| 199 | + maven { |
| 200 | + url "file://${project.projectDir}/repo" |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +tasks.withType(JavaCompile).configureEach { |
| 206 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 207 | +} |
| 208 | + |
| 209 | +// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. |
| 210 | +idea { |
| 211 | + module { |
| 212 | + downloadSources = true |
| 213 | + downloadJavadoc = true |
| 214 | + } |
| 215 | +} |
0 commit comments