Skip to content

Instantly share code, notes, and snippets.

@AzureDoom
Last active February 15, 2022 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AzureDoom/3f0df105ac480c058a486879ebc86520 to your computer and use it in GitHub Desktop.
Save AzureDoom/3f0df105ac480c058a486879ebc86520 to your computer and use it in GitHub Desktop.
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath group: 'gradle.plugin.com.github.johnrengelman', name: 'shadow', version: '7.1.0' // <- Add shadowing plugin into dependencies
}
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow' // <- Apply shadowing plugin to gradle
apply plugin: 'maven-publish'
version = '1.0'
group = 'com.yourname.modid'
archivesBaseName = 'modid'
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
mappings channel: 'official', version: '1.16.5'
runs {
client {
workingDirectory project.file('run')
taskName 'Client'
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
taskName 'Server'
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
taskName 'DataGen'
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
examplemod {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
repositories {
maven {
name = "Geckolib" // Geckolib
url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/" // <- Add geckolib into repositories (may need to create repositories section)
}
}
configurations {
shade // <- Create a 'shade' configuration
implementation.extendsFrom(shade) // <- Add the shade configuration to implementation
}
dependencies {
minecraft 'net.minecraftforge:forge:1.16.5-36.2.19'
shade fg.deobf('software.bernie.geckolib:geckolib-forge-1.16.5:3.0.56') // <- Add GeckoLib to shade configuration. This also includes it as an in-dev dependency due to shade extending implementation
}
// Create shadowJar task
shadowJar {
configurations = [project.configurations.shade] // <- Tell shadowJar to shade dependencies from 'shade'
// Skip unnecessary assets and duplicated java files GeckoLib comes with
exclude 'software/bernie/example/**'
exclude 'assets/geckolib3/**'
exclude '**/*.java'
relocate 'software.bernie.shadowed', 'software.bernie.modid.shadowed' // <- Move the shadowed geckolib shadowed packages. This prevents classpath conflicts in runtime
relocate 'software.bernie.geckolib', 'software.bernie.modid.geckolib' // <- Move the shadowed geckolib package. This prevents classpath conflicts in runtime
classifier ''
finalizedBy 'reobfShadowJar' // <- Finish shading with reobfuscation
}
artifacts {
archives tasks.shadowJar // <- Add the shadowJar task to the archives configuration
}
reobf { // <- Add the output of shadowJar to reobfuscation, so shadowed content is reobfuscated
shadowJar {}
}
jar {
manifest {
attributes([
"Specification-Title": "examplemod",
"Specification-Vendor": "examplemodsareus",
"Specification-Version": "1",
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"examplemodsareus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
jar.finalizedBy('reobfJar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment