mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-14 01:04:24 +00:00
168 lines
7.4 KiB
Groovy
168 lines
7.4 KiB
Groovy
// Don't see a feature you're wanting to use?
|
|
// See our MDKExamples repository for minimal examples for features like JarInJar
|
|
// https://github.com/MinecraftForge/MDKExamples
|
|
plugins {
|
|
id 'eclipse'
|
|
id 'idea'
|
|
id 'java'
|
|
id 'maven-publish'
|
|
id 'net.minecraftforge.gradle' version '[7.0,8)'
|
|
id 'net.minecraftforge.renamer' version '1.1.8+' // Required on all versions which use SRG maps at runtime.
|
|
}
|
|
|
|
version = '1.0'
|
|
group = 'com.example'
|
|
base.archivesName = 'examplemod'
|
|
|
|
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
|
|
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
|
|
|
println "Java: ${providers.systemProperty('java.version').get()}, " +
|
|
"JVM: ${providers.systemProperty('java.vm.version').get()} (${providers.systemProperty('java.vendor').get()}), " +
|
|
"Arch: ${providers.systemProperty('os.arch').get()}"
|
|
|
|
minecraft {
|
|
// Declare which mappings to use
|
|
mappings channel: mapping_channel, version: minecraft_version
|
|
|
|
// Access Transformer files may now be automatically detected, or explicitly declared.
|
|
// Setting the below flag will cause ForgeGradle to look for META-INF/accesstransformer.cfg
|
|
// Alternatively, provide it a file(<path>) or files(<paths>) for explicitly declared files. If you use any
|
|
// explicitly declared access transformers, all transformers must be also declared in the mods.toml
|
|
// accessTransformer = true
|
|
|
|
runs {
|
|
configureEach {
|
|
workingDir.convention layout.projectDirectory.dir('run')
|
|
|
|
//systemProperty 'forge.logging.markers', 'REGISTRIES'
|
|
|
|
//args "-mixin.config=${mod_id}.mixins.json"
|
|
}
|
|
|
|
register('client') {
|
|
systemProperty 'forge.enabledGameTestNamespaces', mod_id
|
|
}
|
|
|
|
register('server') {
|
|
systemProperty 'forge.enabledGameTestNamespaces', mod_id
|
|
args '--nogui'
|
|
}
|
|
|
|
register('gameTestServer') {
|
|
systemProperty 'forge.enabledGameTestNamespaces', mod_id
|
|
}
|
|
|
|
register('data') {
|
|
workingDir = layout.projectDirectory.dir('run-data')
|
|
|
|
args '--mod', mod_id, '--all', '--output', layout.projectDirectory.dir('src/generated/resources'), '--existing', layout.projectDirectory.dir('src/main/resources')
|
|
}
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
minecraft.mavenizer(it)
|
|
maven fg.forgeMaven
|
|
maven fg.minecraftLibsMaven
|
|
// Needed for JEI
|
|
// maven { url = 'https://maven.blamejared.com/' }
|
|
}
|
|
|
|
dependencies {
|
|
// Minecraft/Forge itself
|
|
implementation minecraft.dependency("net.minecraftforge:forge:$minecraft_version-$forge_version")
|
|
// A 3rd party mod, which needs to be deobfuscated from SRG names to the mappings we're using
|
|
// implementation renamer.dependency('mezz.jei:jei-1.20.1-forge:15.20.0.129')
|
|
// annotationProcessor 'org.spongepowered:mixin:0.8.7:processor'
|
|
}
|
|
|
|
// This block of code expands all declared replace properties in the specified resource targets.
|
|
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
|
|
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
|
|
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
|
|
tasks.named('processResources', ProcessResources) {
|
|
var replaceProperties = [
|
|
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
|
|
forge_version: forge_version, forge_version_range: forge_version_range,
|
|
loader_version_range: loader_version_range,
|
|
mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
|
|
mod_authors: mod_authors, mod_description: mod_description,
|
|
]
|
|
inputs.property('replaceProperties', replaceProperties)
|
|
|
|
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
|
|
expand replaceProperties
|
|
}
|
|
}
|
|
|
|
// Example for how to get properties into the manifest for reading at runtime.
|
|
tasks.named('jar', Jar) {
|
|
manifest {
|
|
attributes([
|
|
'Specification-Title' : mod_id,
|
|
'Specification-Vendor' : mod_authors,
|
|
'Specification-Version' : '1', // We are version 1 of ourselves
|
|
'Implementation-Title' : project.name,
|
|
'Implementation-Version' : project.jar.archiveVersion,
|
|
'Implementation-Vendor' : mod_authors
|
|
])
|
|
//attributes['MixinConfigs'] = "${mod_id}.mixins.json"
|
|
}
|
|
// This artifact will not be renamed. While this will not launch in production
|
|
// the artifact may be helpful for other developers if your mod is used as a library.
|
|
// By assigning this archive classifier, jar file name will end in '-unobfuscated'
|
|
// e.g. 'examplemod-1.0-unobfuscated.jar'
|
|
archiveClassifier = 'unobfuscated'
|
|
}
|
|
|
|
// Set the default mappings file to our default minecraft dependency
|
|
// This must be done after `minecraft.dependency('coords')` has been done so that gradle knows what dependency we want
|
|
// This mapping will be used by default for all renamer tasks, including deobfuscating dependencies
|
|
// You can still override each specific task, this is just to save repeating yourself in your buildscript.
|
|
renamer.mappings.from minecraft.dependency.toSrgFile
|
|
|
|
// If you are choosing to use mixins, you must give Renamer the additional information for it to handle the refmaps.
|
|
//renamer.enableMixinRefmaps {
|
|
// config "${mod_id}.mixins.json"
|
|
// refMap "${mod_id}.refmap.json"
|
|
//}
|
|
|
|
// Creates a task named 'renameJar'
|
|
renamer.classes(tasks.named('jar', Jar)) {
|
|
// This artifact will be remapped according to the provided mappings file
|
|
// Setting the classifier to '' will attach no extra details to the file name.
|
|
// e.g. 'examplemod-1.0.jar'
|
|
archiveClassifier = ''
|
|
// Unless set globally like above, You need to point to the mappings you wish to apply, typically this is
|
|
// the Mapped names to SRG for older versions.
|
|
// ForgeGradle/Mavenizer generate these files for the dependencies you declare. So you can use the helper.
|
|
// Or you can specify the file or dependency if you host them yourself.
|
|
// map.from minecraft.dependency.toSrgFile
|
|
|
|
// The mixin AP does not include all annotated entries, instead containing some in the augmented mappings.
|
|
// So, if you are using mixins or have dependencies which use them, uncomment the below line to tell renamer
|
|
// that the generated mappings are available. See the MDKExample for more details.
|
|
// mappings renamer.mixin.generatedMappings
|
|
}
|
|
|
|
// Example configuration to allow publishing using the maven-publish plugin
|
|
// We recommend publishing all of your artifacts to publicly accessible maven so that others can easily consume them as dependencies
|
|
publishing {
|
|
repositories {
|
|
// Publishing to a local folder makes it easy to see exactly what you would publish to a real server
|
|
maven { url = layout.projectDirectory.dir('repo').asFile.toURI() }
|
|
}
|
|
|
|
publications.register('mavenJava', MavenPublication) {
|
|
from components.java // Publish the normal jar
|
|
artifact renameJar // Publish the renamed jar in addition
|
|
}
|
|
}
|
|
|
|
tasks.withType(JavaCompile).configureEach {
|
|
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
|
}
|
|
|
|
// IntelliJ no longer downloads javadocs and sources by default, this tells Gradle to force IntelliJ to do it.
|
|
idea.module { downloadJavadoc = downloadSources = true } |