|
| 1 | +plugins { |
| 2 | + id 'java-library' |
| 3 | + id 'maven-publish' |
| 4 | + id 'net.neoforged.moddev' version '1.0.21' |
| 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 | +version = mod_version |
| 17 | +group = mod_group_id |
| 18 | + |
| 19 | +repositories { |
| 20 | + mavenLocal() |
| 21 | +} |
| 22 | + |
| 23 | +base { |
| 24 | + archivesName = mod_id |
| 25 | +} |
| 26 | + |
| 27 | +// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21. |
| 28 | +java.toolchain.languageVersion = JavaLanguageVersion.of(21) |
| 29 | + |
| 30 | +neoForge { |
| 31 | + // Specify the version of NeoForge to use. |
| 32 | + version = project.neo_version |
| 33 | + |
| 34 | + parchment { |
| 35 | + mappingsVersion = project.parchment_mappings_version |
| 36 | + minecraftVersion = project.parchment_minecraft_version |
| 37 | + } |
| 38 | + |
| 39 | + // This line is optional. Access Transformers are automatically detected |
| 40 | + // accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg') |
| 41 | + |
| 42 | + // Default run configurations. |
| 43 | + // These can be tweaked, removed, or duplicated as needed. |
| 44 | + runs { |
| 45 | + client { |
| 46 | + client() |
| 47 | + |
| 48 | + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. |
| 49 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 50 | + } |
| 51 | + |
| 52 | + server { |
| 53 | + server() |
| 54 | + programArgument '--nogui' |
| 55 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 56 | + } |
| 57 | + |
| 58 | + // This run config launches GameTestServer and runs all registered gametests, then exits. |
| 59 | + // By default, the server will crash when no gametests are provided. |
| 60 | + // The gametest system is also enabled by default for other run configs under the /test command. |
| 61 | + gameTestServer { |
| 62 | + type = "gameTestServer" |
| 63 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 64 | + } |
| 65 | + |
| 66 | + data { |
| 67 | + data() |
| 68 | + |
| 69 | + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it |
| 70 | + // gameDirectory = project.file('run-data') |
| 71 | + |
| 72 | + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. |
| 73 | + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() |
| 74 | + } |
| 75 | + |
| 76 | + // applies to all the run configs above |
| 77 | + configureEach { |
| 78 | + // Recommended logging data for a userdev environment |
| 79 | + // The markers can be added/remove as needed separated by commas. |
| 80 | + // "SCAN": For mods scan. |
| 81 | + // "REGISTRIES": For firing of registry events. |
| 82 | + // "REGISTRYDUMP": For getting the contents of all registries. |
| 83 | + systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 84 | + |
| 85 | + // Recommended logging level for the console |
| 86 | + // You can set various levels here. |
| 87 | + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels |
| 88 | + logLevel = org.slf4j.event.Level.DEBUG |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + mods { |
| 93 | + // define mod <-> source bindings |
| 94 | + // these are used to tell the game which sources are for which mod |
| 95 | + // mostly optional in a single mod project |
| 96 | + // but multi mod projects should define one per mod |
| 97 | + "${mod_id}" { |
| 98 | + sourceSet(sourceSets.main) |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Include resources generated by data generators. |
| 104 | +sourceSets.main.resources { srcDir 'src/generated/resources' } |
| 105 | + |
| 106 | +// Sets up a dependency configuration called 'localRuntime'. |
| 107 | +// This configuration should be used instead of 'runtimeOnly' to declare |
| 108 | +// a dependency that will be present for runtime testing but that is |
| 109 | +// "optional", meaning it will not be pulled by dependents of this mod. |
| 110 | +configurations { |
| 111 | + runtimeClasspath.extendsFrom localRuntime |
| 112 | +} |
| 113 | + |
| 114 | +dependencies { |
| 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 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 123 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 124 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 125 | + // implementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 126 | + |
| 127 | + // Example mod dependency using a file as dependency |
| 128 | + // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") |
| 129 | + |
| 130 | + // Example project dependency using a sister or child project: |
| 131 | + // implementation project(":myproject") |
| 132 | + |
| 133 | + // For more info: |
| 134 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 135 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 136 | +} |
| 137 | + |
| 138 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 139 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 140 | +var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) { |
| 141 | + var replaceProperties = [ |
| 142 | + minecraft_version : minecraft_version, |
| 143 | + minecraft_version_range: minecraft_version_range, |
| 144 | + neo_version : neo_version, |
| 145 | + neo_version_range : neo_version_range, |
| 146 | + loader_version_range : loader_version_range, |
| 147 | + mod_id : mod_id, |
| 148 | + mod_name : mod_name, |
| 149 | + mod_license : mod_license, |
| 150 | + mod_version : mod_version, |
| 151 | + mod_authors : mod_authors, |
| 152 | + mod_description : mod_description |
| 153 | + ] |
| 154 | + inputs.properties replaceProperties |
| 155 | + expand replaceProperties |
| 156 | + from "src/main/templates" |
| 157 | + into "build/generated/sources/modMetadata" |
| 158 | +} |
| 159 | +// Include the output of "generateModMetadata" as an input directory for the build |
| 160 | +// this works with both building through Gradle and the IDE. |
| 161 | +sourceSets.main.resources.srcDir generateModMetadata |
| 162 | +// To avoid having to run "generateModMetadata" manually, make it run on every project reload |
| 163 | +neoForge.ideSyncTask generateModMetadata |
| 164 | + |
| 165 | +// Example configuration to allow publishing using the maven-publish plugin |
| 166 | +publishing { |
| 167 | + publications { |
| 168 | + register('mavenJava', MavenPublication) { |
| 169 | + from components.java |
| 170 | + } |
| 171 | + } |
| 172 | + repositories { |
| 173 | + maven { |
| 174 | + url "file://${project.projectDir}/repo" |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +tasks.withType(JavaCompile).configureEach { |
| 180 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 181 | +} |
| 182 | + |
| 183 | +// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. |
| 184 | +idea { |
| 185 | + module { |
| 186 | + downloadSources = true |
| 187 | + downloadJavadoc = true |
| 188 | + } |
| 189 | +} |
0 commit comments