Files
UniMix/build.gradle
T

478 lines
14 KiB
Groovy

// Gradle repositories and dependencies
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
}
}
// Apply plugin
apply plugin: 'java'
apply plugin: 'license'
apply plugin: 'checkstyle'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.github.johnrengelman.shadow'
// Default tasks
defaultTasks 'licenseFormat', 'check', 'build'
// Basic project information
group = 'org.spongepowered'
archivesBaseName = 'mixin'
version = buildVersion + (buildType == 'RELEASE' ? '' : "-$buildType")
// Extended project information
ext.projectName = 'Mixin'
ext.inceptionYear = '2014'
ext.packaging = 'jar'
// Define variables
ext.buildNumber = project.hasProperty("buildNumber") ? buildNumber : '0'
ext.ciSystem = project.hasProperty("ciSystem") ? ciSystem : 'unknown'
ext.commit = project.hasProperty("commit") ? commit : 'unknown'
// Location to store renamed packages
ext.renamedPackageRoot = new File("build/renamed-packages/")
// True to do jar signing task
ext.doSignJar = project.hasProperty("keyStorePath")
// Minimum version of Java required
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
// Project repositories
repositories {
mavenCentral()
maven {
name = 'minecraft'
url = 'https://libraries.minecraft.net/'
}
maven {
name = 'renamed-packages'
url = file(renamedPackageRoot)
}
maven {
// For fernflower
name = 'sponge'
url = 'http://repo.spongepowered.org/maven'
}
}
configurations {
deployerJars // maven stuff
asm // renamer input
jarjar // renamer task
// Exclude non-repackaged ASM so that we don't use it by mistake
compile.exclude module: 'asm-debug-all'
}
// Include annotation processor sourceSet
sourceSets {
ap {
compileClasspath += main.output
}
fernflower {
compileClasspath += main.output
}
agent {
compileClasspath += main.output
}
bridge {
compileClasspath += main.output
}
example {
compileClasspath += main.output
compileClasspath += ap.output
}
launchwrapper {
compileClasspath += main.output
}
}
// Dependencies for renamed ASM
dependencies {
asm 'org.ow2.asm:asm-debug-all:5.2'
asm 'org.ow2.asm:asm-debug-all:5.2:sources'
jarjar 'com.googlecode.jarjar:jarjar:1.1'
}
// Task to read ASM library and rename packages
task renamedASM {
outputs.file files(configurations.asm.files.withIndex().collect { file, i -> def dep = configurations.asm.dependencies[i]
new File(new File(renamedPackageRoot, "org/spongepowered/mixin-" + dep.name + "/" + dep.version), "mixin-" + file.name).path
})
ant {
taskdef (
name: "jarjar",
classname: "com.tonicsystems.jarjar.JarJarTask",
classpath: configurations.jarjar.asPath,
)
outputs.files.eachWithIndex { elem, index ->
logger.info "Generating renamed jar {}", elem.name
def inJar = configurations.asm.files[index]
if (elem.name.contains("sources")) {
def tmpDir = new File(temporaryDir, elem.name + ".tmp")
def rootOld = new File(tmpDir, "org/objectweb")
def tmpOld = new File(rootOld, "asm")
def tmpNew = new File(tmpDir, "org/spongepowered/asm/lib")
unzip (src: inJar, dest: tmpDir)
replace (dir: tmpDir, token: "org.objectweb.asm", value: "org.spongepowered.asm.lib")
move (file: tmpOld, tofile: tmpNew)
delete rootOld
jar (destFile: new File(elem.path)) { fileset(dir: tmpDir) }
delete tmpDir
} else {
jarjar (jarfile: elem.path) {
zipfileset (src: inJar)
rule (
pattern: "org.objectweb.asm.**",
result: "org.spongepowered.asm.lib.@1"
)
}
}
}
}
project.dependencies.add('compile', 'org.spongepowered:mixin-asm-debug-all:5.2')
project.dependencies.add('apCompile', 'org.spongepowered:mixin-asm-debug-all:5.2')
project.dependencies.add('agentCompile', 'org.spongepowered:mixin-asm-debug-all:5.2')
}
eclipseClasspath.dependsOn(renamedASM)
// Project dependencies
dependencies {
def guava = 'com.google.guava:guava:17.0'
def log4j2 = 'org.apache.logging.log4j:log4j-core:2.0-beta9'
compile guava
compile log4j2
compile 'commons-io:commons-io:2.4'
compile 'com.google.code.gson:gson:2.2.4'
compile files(tasks.renamedASM.outputs.files[0]) // Establish implicit dependency on remapped ASM
// Tests
// testCompile 'junit:junit:4.11'
// testCompile 'org.hamcrest:hamcrest-library:1.3'
// testCompile 'org.mockito:mockito-core:1.9.0'
// Annotation Processor
apCompile guava
// AP extension example
exampleCompile configurations.compile
// Maven FTP
deployerJars 'org.apache.maven.wagon:wagon-ftp:2.7'
// Fernflower decompiler
fernflowerCompile configurations.compile
fernflowerCompile 'org.jetbrains.java.decompiler:fernflower:sponge-SNAPSHOT'
// LegacyLauncher service
launchwrapperCompile configurations.compile
launchwrapperCompile('net.minecraft:launchwrapper:1.11') {
exclude module: 'lwjgl'
}
// agent
agentCompile configurations.compile
// asm bridge
bridgeCompile log4j2
bridgeCompile 'org.ow2.asm:asm-commons:5.0.3'
}
// Eclipse
eclipse.classpath.plusConfigurations += [
configurations.fernflowerCompile,
configurations.launchwrapperCompile,
configurations.bridgeCompile
]
// IntelliJ
idea.module.scopes.COMPILE.plus += [
configurations.fernflowerCompile,
configurations.launchwrapperCompile,
configurations.bridgeCompile
]
// Filter, process, and include resources
processResources {
// Include in final JAR
from 'LICENSE.txt'
}
// License header formatting
license {
ext {
name = project.name
organization = project.organization
url = project.url
}
include '**/*.java'
header file("HEADER.txt")
sourceSets = project.sourceSets
ignoreFailures false
strictCheck true
mapping {
java = 'SLASHSTAR_STYLE'
}
}
checkstyle {
configProperties = [
"name" : project.name,
"organization": project.organization,
"url" : project.url,
"year" : project.inceptionYear
]
configFile = file("checkstyle.xml")
toolVersion = '8.10'
}
// Source compiler configuration
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xlint:all', '-Xlint:-path']
options.deprecation = true
options.encoding = 'utf8'
}
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
// disable the crazy super-strict doclint tool in Java 8
options.addStringOption('Xdoclint:none', '-quiet')
}
}
jar {
// Include annotation processor
from sourceSets.ap.output
// Include fernflower bridge
from sourceSets.fernflower.output
// Include hotswap agent
from sourceSets.agent.output
// Bridge
from sourceSets.bridge.output
// Launchwrapper
from sourceSets.launchwrapper.output
// Renamed ASM
from zipTree(tasks.renamedASM.outputs.files[0]).matching {
include 'org/spongepowered/asm/lib/*'
include 'org/spongepowered/asm/lib/commons/ClassRemapper*'
include 'org/spongepowered/asm/lib/commons/Remapper*'
include 'org/spongepowered/asm/lib/commons/SignatureRemapper*'
include 'org/spongepowered/asm/lib/signature/**'
include 'org/spongepowered/asm/lib/tree/**'
include 'org/spongepowered/asm/lib/util/**'
}
exclude 'org/objectweb/**'
// JAR manifest configuration
manifest.mainAttributes(
"Built-By": System.properties['user.name'],
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
"Implementation-Title": name,
"Implementation-Version": version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit,
"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
)
if (project.doSignJar) {
classifier = 'unsigned'
}
}
task thinJar(type: Jar) {
from sourceSets.main.output
from zipTree(tasks.renamedASM.outputs.files[0])
classifier = 'thin'
exclude 'org/objectweb/**'
exclude 'org/spongepowered/asm/lib/commons/**'
exclude 'org/spongepowered/asm/lib/signature/**'
exclude 'org/spongepowered/asm/lib/tree/analysis/**'
exclude 'org/spongepowered/asm/lib/xml/**'
exclude 'org/spongepowered/asm/launch/**'
exclude 'org/spongepowered/asm/mixin/injection/invoke/**'
exclude 'org/spongepowered/asm/mixin/transformer/*.class'
exclude 'org/spongepowered/asm/mixin/transformer/debug/**'
exclude 'org/spongepowered/asm/mixin/transformer/verify/**'
manifest.mainAttributes(
"Built-By": System.properties['user.name'],
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
"Implementation-Title": name,
"Implementation-Version": version + "+" + ciSystem + "-b" + buildNumber + ".git-" + commit,
"Implementation-Vendor": url,
)
}
build.dependsOn(thinJar)
// generate shadow jar so we can use the AP standalone
shadowJar {
from sourceSets.ap.output
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
dependencies {
include(dependency('com.google.guava:guava'))
include(dependency('com.google.code.gson:gson'))
include(dependency('commons-io:commons-io'))
include(dependency('org.apache.logging.log4j:log4j-core'))
include(dependency('org.apache.logging.log4j:log4j-api'))
}
classifier = 'processor'
}
build.dependsOn(shadowJar)
if (project.doSignJar) {
// Clear artifacts because jar will be there by default
configurations.archives.artifacts.clear()
// Define signjar task
task signJar() {
inputs.files(jar.outputs)
outputs.file jar.outputs.files.collect {
new File(it.parent, it.name.replace('-unsigned', ''))
}
doLast {
jar.outputs.files.each {
ant.signjar(
alias: project.keyStoreCert,
jar: it,
signedJar: new File(it.parent, it.name.replace('-unsigned', '')),
keystore: project.keyStorePath,
storepass: project.keyStoreSecret,
keypass: project.keyStoreSecret,
tsaurl: project.timestampAuthority,
preservelastmodified: 'true'
)
}
}
}
build.dependsOn(signJar)
}
// 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.classifier = new Date().format('yyyyMMddHHmmss')
}
}
task sourceJar(type: Jar) {
from sourceSets.main.java
from sourceSets.main.resources
from sourceSets.ap.java
from sourceSets.ap.resources
from sourceSets.fernflower.java
from sourceSets.fernflower.resources
from sourceSets.agent.java
from sourceSets.agent.resources
from sourceSets.bridge.java
from sourceSets.bridge.resources
from sourceSets.example.java
from sourceSets.example.resources
classifier = "sources"
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier = "javadoc"
}
artifacts {
if (project.doSignJar) {
archives signJar.outputs.files[0]
}
archives thinJar
archives sourceJar
archives javadocJar
}
ext.excludePomDeps = [
'fernflower',
'jarjar',
'hamcrest-library',
'junit',
'mockito-core',
'mixin-asm-debug-all',
'log4j-core'
]
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
if (project.hasProperty("chRepo")) {
repository(url: project.chRepo) {
authentication(userName: project.chUsername, password: project.chPassword)
}
}
pom {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description project.projectName
url 'http://www.spongepowered.org/'
scm {
url 'https://github.com/SpongePowered/Mixin'
connection 'scm:git:git://github.com/SpongePowered/Mixin.git'
developerConnection 'scm:git:[email protected]:SpongePowered/Mixin.git'
}
issueManagement {
system 'GitHub Issues'
url 'https://github.com/SpongePowered/Mixin/issues'
}
licenses {
license {
name 'MIT license'
url 'http://opensource.org/licenses/MIT'
distribution 'repo'
}
}
}
whenConfigured {
dependencies = dependencies.findAll {
!it.artifactId.matches(excludePomDeps.join('|'))
}
}
}
}
}
}
install.repositories.mavenInstaller.pom {
whenConfigured {
dependencies = dependencies.findAll {
!it.artifactId.matches(excludePomDeps.join('|'))
}
}
}