|
| 1 | +plugins { |
| 2 | + id 'java' |
| 3 | + id 'idea' |
| 4 | + id 'eclipse' |
| 5 | + id 'maven-publish' |
| 6 | + id 'net.minecraftforge.accesstransformers' version '5.0.1' |
| 7 | + id 'net.minecraftforge.gradle' version '7.0.0-beta.46' |
| 8 | + id 'net.minecraftforge.jarjar' version '0.2.3' |
| 9 | +} |
| 10 | + |
| 11 | +version = mod_version |
| 12 | +group = mod_group_id |
| 13 | +base.archivesName = mod_id |
| 14 | + |
| 15 | +// Mojang ships Java 21 to end users in 1.20.5+, so your mod should target Java 21. |
| 16 | +java.toolchain.languageVersion = JavaLanguageVersion.of(21) |
| 17 | + |
| 18 | +println "Java: ${providers.systemProperty('java.version').get()}, " + |
| 19 | + "JVM: ${providers.systemProperty('java.vm.version').get()} (${providers.systemProperty('java.vendor').get()}), " + |
| 20 | + "Arch: ${providers.systemProperty('os.arch').get()}" |
| 21 | + |
| 22 | +minecraft { |
| 23 | + mappings channel: mapping_channel, version: mapping_version |
| 24 | + |
| 25 | + accessTransformers = true |
| 26 | + |
| 27 | + runs { |
| 28 | + configureEach { |
| 29 | + workingDir.convention layout.projectDirectory.dir('run') |
| 30 | + |
| 31 | + //systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 32 | + |
| 33 | + systemProperty 'forge.logging.console.level', 'debug' |
| 34 | + |
| 35 | + systemProperty 'eventbus.api.strictRuntimeChecks', 'true' |
| 36 | + |
| 37 | + //args "-mixin.config=${mod_id}.mixins.json" |
| 38 | + } |
| 39 | + |
| 40 | + register('client') { |
| 41 | + systemProperty 'forge.enabledGameTestNamespaces', mod_id |
| 42 | + } |
| 43 | + |
| 44 | + register('server') { |
| 45 | + systemProperty 'forge.enabledGameTestNamespaces', mod_id |
| 46 | + args '--nogui' |
| 47 | + } |
| 48 | + |
| 49 | + register('gameTestServer') { |
| 50 | + systemProperty 'forge.enabledGameTestNamespaces', mod_id |
| 51 | + } |
| 52 | + |
| 53 | + register('data') { |
| 54 | + workingDir = layout.projectDirectory.dir('run-data') |
| 55 | + |
| 56 | + args '--mod', mod_id, '--all', '--output', layout.projectDirectory.dir('src/generated/resources'), '--existing', layout.projectDirectory.dir('src/main/resources') |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// Include resources generated by data generators. |
| 62 | +sourceSets.main.resources { srcDir layout.projectDirectory.dir('src/generated/resources') } |
| 63 | + |
| 64 | +// This methods registers jarJar for the default jar task. |
| 65 | +// The closure allows you to configure the task, instead of needing to do this: |
| 66 | +// tasks.named('jarJar', net.minecraftforge.jarjar.gradle.JarJar) |
| 67 | +jarJar.register() { |
| 68 | + archiveClassifier = null |
| 69 | +} |
| 70 | + |
| 71 | +repositories { |
| 72 | + maven minecraft.mavenizer |
| 73 | + maven fg.forgeMaven |
| 74 | + maven fg.minecraftLibsMaven |
| 75 | + exclusiveContent { |
| 76 | + forRepository { |
| 77 | + maven { |
| 78 | + name = 'Sponge' |
| 79 | + url = 'https://repo.spongepowered.org/repository/maven-public' |
| 80 | + } |
| 81 | + } |
| 82 | + filter { |
| 83 | + includeGroupAndSubgroups('org.spongepowered') |
| 84 | + } |
| 85 | + } |
| 86 | + mavenCentral() |
| 87 | + mavenLocal() |
| 88 | + |
| 89 | + // If you have mod jar dependencies in ./libs, you can declare them as a repository like so. |
| 90 | + // See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver |
| 91 | + // NOTE: Support for local dependencies is still experimental in ForgeGradle 7. |
| 92 | + //flatDir { |
| 93 | + // dir 'libs' |
| 94 | + //} |
| 95 | +} |
| 96 | + |
| 97 | +dependencies { |
| 98 | + // Specify the version of Minecraft to use. |
| 99 | + // Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact. |
| 100 | + // The "userdev" classifier will be requested and setup by ForgeGradle. |
| 101 | + // If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"], |
| 102 | + // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. |
| 103 | + implementation minecraft.dependency("net.minecraftforge:forge:$minecraft_version-$forge_version") |
| 104 | + |
| 105 | + // Forge 1.21.6+ uses EventBus 7, which shifts most of its runtime validation to compile-time via an annotation processor |
| 106 | + // to improve performance in production environments. This line is required to enable said compile-time validation |
| 107 | + // in your development environment, helping you catch issues early. |
| 108 | + annotationProcessor 'net.minecraftforge:eventbus-validator:7.0-beta.10' |
| 109 | + |
| 110 | + // Example mod dependency with JEI |
| 111 | + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime |
| 112 | + //compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" |
| 113 | + //compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}" |
| 114 | + //runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}" |
| 115 | + |
| 116 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 117 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 118 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 119 | + // NOTE: Support for deobfuscated dependencies has not yet been added in ForgeGradle 7. |
| 120 | + //implementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 121 | + |
| 122 | + // For more info: |
| 123 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 124 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 125 | +} |
| 126 | + |
| 127 | +tasks.withType(JavaCompile).configureEach { |
| 128 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 129 | +} |
| 130 | + |
| 131 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 132 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 133 | +// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. |
| 134 | +// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html |
| 135 | +tasks.named('processResources', ProcessResources) { |
| 136 | + var replaceProperties = [ |
| 137 | + minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, |
| 138 | + forge_version: forge_version, forge_version_range: forge_version_range, |
| 139 | + loader_version_range: loader_version_range, |
| 140 | + mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, |
| 141 | + mod_authors: mod_authors, mod_description: mod_description, |
| 142 | + ] |
| 143 | + inputs.property('replaceProperties', replaceProperties) |
| 144 | + |
| 145 | + filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { |
| 146 | + expand replaceProperties |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +// Example for how to get properties into the manifest for reading at runtime. |
| 151 | +tasks.named('jar', Jar) { |
| 152 | + manifest { |
| 153 | + attributes([ |
| 154 | + 'Specification-Title' : mod_id, |
| 155 | + 'Specification-Vendor' : mod_authors, |
| 156 | + 'Specification-Version' : '1', // We are version 1 of ourselves |
| 157 | + 'Implementation-Title' : project.name, |
| 158 | + 'Implementation-Version' : project.jar.archiveVersion, |
| 159 | + 'Implementation-Vendor' : mod_authors |
| 160 | + ]) |
| 161 | + //attributes['MixinConfigs'] = "${mod_id}.mixins.json" |
| 162 | + } |
| 163 | + |
| 164 | + archiveClassifier = 'slim' |
| 165 | +} |
| 166 | + |
| 167 | +// Example configuration to allow publishing using the maven-publish plugin |
| 168 | +publishing { |
| 169 | + repositories { |
| 170 | + maven { url = "file://${layout.projectDirectory.asFile}/mcmodsrepo" } |
| 171 | + } |
| 172 | + |
| 173 | + publications.register('mavenJava', MavenPublication) { |
| 174 | + // the java component publishes the jar output as the primary artifact |
| 175 | + //from components.java |
| 176 | + |
| 177 | + // the jarJar component publishes the jarJar output as the primary artifact |
| 178 | + from components.jarJar |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +// IntelliJ no longer downloads javadocs and sources by default, this tells Gradle to force IntelliJ to do it. |
| 183 | +idea.module { downloadJavadoc = downloadSources = true } |
| 184 | + |
| 185 | +eclipse { |
| 186 | + // Eclipse no longer downloads javadocs and sources by default, this tells Gradle to force Eclipse to do it. |
| 187 | + classpath { downloadJavadoc = downloadSources = true } |
| 188 | + |
| 189 | + // NOTE: ForgeGradle 7 does not yet support Eclipse run configurations |
| 190 | + // Run everytime eclipse builds the code |
| 191 | + //autoBuildTasks genEclipseRuns |
| 192 | + // Run when importing the project |
| 193 | + //synchronizationTasks 'genEclipseRuns' |
| 194 | +} |
| 195 | + |
| 196 | +// NOTE: Merging of source sets is now controlled by the property 'net.minecraftforge.gradle.merge-source-sets' |
0 commit comments