Files
UniMix/build.gradle
2026-03-03 17:04:03 +03:00

580 lines
18 KiB
Groovy

// Gradle repositories and dependencies
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:' + (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11) ? '7.5.0' : '7.1.0')
}
}
plugins {
// id "me.modmuss50.remotesign" version "0.5.0"
id "com.gradleup.shadow" version "9.0.0-beta17"
id "dev.lukebemish.central-portal-publishing" version "0.1.7"
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
// Apply plugin
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'potemkin-modules'
// Default tasks
defaultTasks 'check', 'build'
// Basic project information
group = 'io.github.legacymoddingmc'
version = buildVersion + "+mixin." + upstreamMixinVersion
base {
archivesName = 'sponge-mixin'
}
def ENV = System.getenv()
if (!ENV.CI) {
version = version + "-local"
}
// Extended project information
ext.projectName = 'Mixin'
ext.inceptionYear = '2014'
ext.packaging = 'jar'
// Define variables
ext.asmVersion = project.hasProperty("asmVersion") ? asmVersion : '9.0'
ext.legacyForgeAsmVersion = project.hasProperty("legacyForgeAsmVersion") ? asmVersion : '5.0.3'
java {
modularity.inferModulePath = false
disableAutoTargetJvm()
// Minimum version of Java required
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
// Project repositories
repositories {
mavenCentral()
maven {
name = 'minecraft'
url = 'https://libraries.minecraft.net/'
}
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
// For modlauncher
name = 'neoforged'
url = 'https://maven.neoforged.net/releases'
}
}
sourceSets {
legacy {
ext.languageVersion = 8
ext.compatibility = '1.8'
}
main {
compileClasspath += legacy.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
ap {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
fernflower {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
ext.modularityExcluded = true
}
agent {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
bridge {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
ext.modularityExcluded = true
}
example {
compileClasspath += main.output
compileClasspath += ap.output
ext.modularityExcluded = true
}
test {
ext.modularityExcluded = true
}
launchwrapper {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher4 {
compileClasspath += main.output
compileClasspath += modlauncher.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher9 {
ext.languageVersion = 16
compileClasspath += main.output
compileClasspath += modlauncher.output
}
modularity {
ext.languageVersion = 16
ext.modularityExcluded = true // don't add ourselves
}
modularityDummy {}
}
configurations {
stagingJar
exampleImplementation .extendsFrom implementation
fernflowerImplementation .extendsFrom implementation
launchwrapperImplementation .extendsFrom implementation
agentImplementation .extendsFrom implementation
modlauncherImplementation .extendsFrom implementation
modlauncher9Implementation .extendsFrom modlauncherImplementation
modularityImplementation .extendsFrom modlauncher9Implementation
modularityCompileOnly .extendsFrom compileOnly
proguard {
extendsFrom fernflowerImplementation
extendsFrom launchwrapperImplementation
extendsFrom modlauncherImplementation
extendsFrom compileClasspath
}
}
// Because Mixin aims to support a variety of environments, we have to be able to run with older versions of GSON and Guava that lack official module
// names. This means the same library may appear with multiple module names. We want to be able to link our module with either of these two at
// runtime, without having to have two versions of the library on our compile-time module path. To do this, we generate empty "potemkin" jars with
// *only* a module descriptor for the module we want to be able to compile against.
potemkinModules {
module 'com.google.gson'
module 'com.google.common'
}
// Project dependencies
dependencies {
def guava = 'com.google.guava:guava:21.0' // from mc1.12 onwards
def gson = 'com.google.code.gson:gson:2.2.4'
stagingJar guava
stagingJar gson
implementation guava
implementation 'com.google.code.gson:gson:2.2.4'
if (Float.parseFloat(asmVersion) < 6) {
implementation "org.ow2.asm:asm-debug-all:$asmVersion"
}
implementation "org.ow2.asm:asm-tree:$asmVersion"
implementation "org.ow2.asm:asm-commons:$asmVersion"
implementation "org.ow2.asm:asm-util:$asmVersion"
// Annotation Processor
apImplementation "org.ow2.asm:asm-tree:$asmVersion"
apImplementation guava
apImplementation gson
// Fernflower decompiler
fernflowerImplementation 'org.jetbrains:intellij-fernflower:1.0.0.9'
// LegacyLauncher service
launchwrapperImplementation ('net.minecraft:launchwrapper:1.11') {
exclude module: 'lwjgl'
exclude module: 'asm-debug-all'
exclude module: 'jopt-simple'
}
modlauncherImplementation 'net.sf.jopt-simple:jopt-simple:5.0.4'
modlauncherCompileOnly 'org.apache.logging.log4j:log4j-core:2.0-beta9'
modlauncherImplementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") {
exclude module: 'asm'
exclude module: 'asm-analysis'
exclude module: 'asm-commons'
exclude module: 'asm-tree'
exclude module: 'jopt-simple'
}
modlauncher4Implementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") {
exclude module: 'asm'
exclude module: 'asm-analysis'
exclude module: 'asm-commons'
exclude module: 'asm-tree'
exclude module: 'jopt-simple'
}
modlauncher9Implementation ("cpw.mods:modlauncher:$modlauncherVersion") {
exclude module: 'jopt-simple'
}
modlauncher9Implementation 'cpw.mods:securejarhandler:2.1.24'
// asm bridge
bridgeImplementation 'org.apache.logging.log4j:log4j-core:2.0-beta9'
bridgeImplementation "org.ow2.asm:asm-commons:$legacyForgeAsmVersion"
legacyImplementation "org.ow2.asm:asm-tree:$asmVersion"
modularityCompileOnly 'org.apache.logging.log4j:log4j-core:2.11.2'
}
javadoc {
exclude '**/throwables'
classpath += sourceSets.legacy.output
source sourceSets.ap.allJava
options.encoding = 'UTF-8'
exclude {
it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/)
}
options {
docTitle 'Welcome to the Mixin Javadoc'
overview 'docs/javadoc/overview.html'
addBooleanOption '-allow-script-in-comments', true
}
doLast {
copy {
from 'docs/javadoc/resources'
into outputDirectory
}
}
}
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file.whenMerged {
// Can't include old modlauncher because it causes issues with modules
entries.removeAll { it.kind == 'lib' && it.path =~ ~/modlauncher-$legacyModlauncherVersion/ }
entries.removeAll { it.kind == 'src' && it.path =~ ~/modlauncher4/ }
entries.removeAll { it.kind == 'lib' && it.path =~ ~/log4j.*beta9/ }
// Mark everything else as a module
entries.findAll { it.kind == "con" && it.path =~ /gradleclasspathcontainer$/ }.each {
it.entryAttributes['module'] = 'true'
}
}
}
project {
resourceFilter {
appliesTo = 'FOLDERS'
type = 'EXCLUDE_ALL'
matcher {
id = 'org.eclipse.ui.ide.multiFilter'
arguments = '1.0-name-matches-false-false-buildSrc'
}
}
}
// Build service task outputs for test projects
autoBuildTasks compileModlauncher4Java, compileModlauncher9Java, compileLaunchwrapperJava
}
// Filter, process, and include resources
processResources {
// Include in final JAR
from 'LICENSE.txt'
}
// License header formatting
def validateHeaders = tasks.register("validateHeaders", org.spongepowered.asm.mixin.build.ValidateLicenseHeadersTasks) {
header = resources.text.fromFile("HEADER.txt")
source = sourceSets.collect { it.allJava }
}
tasks.check.dependsOn validateHeaders
checkstyle {
configProperties = [
"name" : project.name,
"organization": project.organization,
"url" : project.url,
"year" : project.inceptionYear
]
configFile = file("checkstyle.xml")
toolVersion = '10.17.0'
}
// Source compiler configuration
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xlint:all', '-Xlint:-path', '-proc:none']
options.deprecation = true
options.encoding = 'utf8'
}
def modularityInputs = objects.fileCollection()
project.sourceSets.each { set -> {
if (set.ext.has("languageVersion") && JavaVersion.current().isJava9Compatible()) {
project.tasks[set.compileJavaTaskName].options.release = set.ext.languageVersion
}
if (set.ext.has("compatibility")) {
project.tasks[set.compileJavaTaskName].sourceCompatibility = set.ext.compatibility
project.tasks[set.compileJavaTaskName].targetCompatibility = set.ext.compatibility
}
def modularityExcluded = set.ext.has("modularityExcluded") && set.ext.modularityExcluded
if (!modularityExcluded) {
project.sourceSets.modularity {
compileClasspath += set.output
}
modularityInputs.from set.output
}
}}
compileModularityJava {
inputs.files(modularityInputs)
options.javaModuleVersion = project.version as String
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--patch-module', "org.spongepowered.mixin=${modularityInputs.collect { it.absolutePath }.join(File.pathSeparator)}"
]
}
}
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
// disable the crazy super-strict doclint tool in Java 8
options.addStringOption('Xdoclint:syntax', '-quiet')
}
}
task stagingJar(type: ShadowJar) {
sourceSets.findAll { !(it.name =~ /example|test|modularityDummy/) }.each {
from it.output
}
configurations = [project.configurations.stagingJar]
// JAR manifest configuration
manifest.attributes(
"Built-By": System.properties['user.name'],
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
"Implementation-Title": name,
"Implementation-Version": project.version,
"Implementation-Vendor": url,
// for hotswap agent
"Premain-Class": "org.spongepowered.tools.agent.MixinAgent",
"Agent-Class": "org.spongepowered.tools.agent.MixinAgent",
"Can-Redefine-Classes": true,
"Can-Retransform-Classes": true
)
mergeServiceFiles()
relocate 'com.google', 'org.spongepowered.include.com.google'
archiveClassifier = "staging"
}
File proguardFile = file("build/libs/sponge-mixin-${version}.jar")
task stagingProguardJar(type: proguard.gradle.ProGuardTask, dependsOn: stagingJar) {
doFirst {
configurations.proguard.resolve().forEach {
libraryjars it
}
}
outputs.upToDateWhen { false }
libraryjars JavaVersion.current().java9Compatible ? "${System.getProperty('java.home')}/jmods" : "${System.getProperty('java.home')}/lib/rt.jar"
injars stagingJar.archiveFile
outjars proguardFile
configuration file("proguard.conf")
}
build.dependsOn stagingProguardJar
// Clear artifacts because jar will be there by default and we want to use staging jar instead
configurations.archives.artifacts.clear()
// generate shadow jar so we can use the AP standalone
shadowJar {
from sourceSets.ap.output
archiveClassifier = 'processor'
}
build.dependsOn(shadowJar)
// Run this task instead of build to generate a timestamped shadow jar (for dev)
task timestamp(type: Jar, dependsOn: build) {
if (gradle.startParameter.taskNames.contains(name)) {
shadowJar.archiveClassifier = new Date().format('yyyyMMddHHmmss')
}
}
task sourceJar(type: Jar) {
sourceSets.findAll { it.name != 'modularity' }.each {
from it.java
from it.resources
}
archiveClassifier = "sources"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
archiveClassifier = "javadoc"
}
artifacts {
archives stagingJar
archives sourceJar
archives javadocJar
archives shadowJar
}
ext.excludePomDeps = [
'fernflower',
'jarjar',
'hamcrest-library',
'junit',
'mockito-core',
'mixin-asm-debug-all',
'log4j-core',
'gson'
]
centralPortalPublishing.bundle('mixin') {
username = ENV.MAVEN_CENTRAL_USERNAME
password = ENV.MAVEN_CENTRAL_PASSWORD
}
tasks.publish.dependsOn tasks.named("publishMixinCentralPortalBundle")
publishing {
publications {
developer(MavenPublication) { publication ->
groupId = project.group
artifactId = project.base.archivesName.get()
version = project.version
artifact sourceJar
artifact javadocJar
artifact(proguardFile) {
builtBy stagingProguardJar
classifier = null
}
// https://issues.gradle.org/browse/GRADLE-2966
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.runtimeClasspath.allDependencies.each {
if (it.group != null && it.name != null && !excludePomDeps.contains(it.name)) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
if (it.excludeRules.size() > 0) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
it.excludeRules.each { rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group)
exclusionNode.appendNode('artifactId', rule.module)
}
}
}
}
}
pom {
description = 'LegacyModdingMC fork of Fabric Mixin, a trait/mixin and bytecode weaving framework for Java using ASM.'
url = 'https://github.com/LegacyModdingMC/UniMix'
scm {
connection = "scm:git:https://github.com/LegacyModdingMC/UniMix.git"
developerConnection = "scm:git:[email protected]:LegacyModdingMC/UniMix.git"
url = "https://github.com/LegacyModdingMC/UniMix"
}
issueManagement {
system = "GitHub"
url = "https://github.com/LegacyModdingMC/UniMix/issues"
}
licenses {
license {
name = 'The MIT License'
url = 'https://raw.githubusercontent.com/LegacyModdingMC/UniMix/main/LICENSE.txt'
}
}
developers {
// Et. al. that arent in the fabric org on maven central
developer {
id = "makamys"
name = "makamys"
email = "[email protected]"
}
developer {
id = "modmuss50"
name = "modmuss50"
email = "[email protected]"
}
developer {
id = "sfPlayer"
name = "Player"
email = "[email protected]"
}
}
}
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url = ENV.MAVEN_URL
credentials {
username = ENV.MAVEN_USERNAME
password = ENV.MAVEN_PASSWORD
}
}
}
centralPortalPublishing.portalBundle(':', 'mixin')
}
}
//remoteSign {
// requestUrl = ENV.SIGNING_SERVER
// pgpAuthKey = ENV.SIGNING_PGP_KEY
// useDummyForTesting = ENV.SIGNING_SERVER == null
// sign publishing.publications.developer
//}
// A task to ensure that the version being released has not already been released.
//task checkVersion {
// doFirst {
// def xml = new URL("https://maven.fabricmc.net/net/fabricmc/sponge-mixin/maven-metadata.xml").text
// def metadata = new XmlSlurper().parseText(xml)
// def versions = metadata.versioning.versions.version*.text();
// if (versions.contains(version)) {
// throw new RuntimeException("${version} has already been released!")
// }
// }
//}
//publish.mustRunAfter checkVersion