plugins { id 'java' id 'com.github.johnrengelman.shadow' version '5.2.0' id 'maven-publish' } group = 'cuchaz' version = '0.15.2' def generatedSourcesDir = "$buildDir/generated-src" def buildNumber = System.getenv("BUILD_NUMBER") version = version + "+" + (buildNumber ? "build.$buildNumber" : "local") sourceCompatibility = 1.8 targetCompatibility = 1.8 task generateSources(type: Copy) { from sourceSets.main.java into generatedSourcesDir filter { String line -> ("$line".replaceAll('@VERSION@', version)) } } compileJava.source = generatedSourcesDir compileJava.dependsOn generateSources repositories { mavenLocal() mavenCentral() maven { name "Modmuss Repository" url 'https://maven.modmuss50.me/' } } configurations { proGuard } dependencies { implementation 'com.google.guava:guava:28.0-jre' implementation 'com.google.code.gson:gson:2.8.5' implementation 'org.ow2.asm:asm:8.0' implementation 'org.ow2.asm:asm-commons:8.0' implementation 'org.ow2.asm:asm-tree:8.0' implementation 'org.ow2.asm:asm-util:8.0' implementation 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3' implementation 'net.fabricmc:procyon-fabric-compilertools:0.5.35.13' implementation 'net.fabricmc:cfr:0.0.1' implementation 'com.bulenkov:darcula:1.0.0.1' implementation 'de.sciss:syntaxpane:1.2.0' implementation 'me.xdrop:fuzzywuzzy:1.2.0' testImplementation 'junit:junit:4.+' testImplementation 'org.hamcrest:hamcrest-all:1.+' proGuard 'net.sf.proguard:proguard-base:6.+' } def libraryJarsArg = JavaVersion.current().java9Compatible ? "/jmods": "/lib/rt.jar" // For each set of test inputs, create an output jar and obfuscate it. file('src/test/java/cuchaz/enigma/inputs').listFiles().each { theFile -> if (theFile.directory) { task("${theFile.name}TestJar", type: Jar) { from(sourceSets.test.output) { include "cuchaz/enigma/inputs/$theFile.name/**/*.class" include 'cuchaz/enigma/inputs/Keep.class' } archiveFileName = theFile.name + '.jar' destinationDirectory = file('build/test-inputs') } task("${theFile.name}TestObf", type: JavaExec, dependsOn: "${theFile.name}TestJar") { main 'proguard.ProGuard' classpath configurations.proGuard args '@src/test/resources/proguard-test.conf', '-injars', file('build/test-inputs/' + "${theFile.name}.jar"), '-libraryjars', libraryJarsArg, '-outjars', file('build/test-obf/' + "${theFile.name}.jar") } test.dependsOn "${theFile.name}TestObf" } } // We also semi-deobfuscate translation.jar to then test it... yeah... oh well. task('deobfTranslationInput', type: JavaExec, dependsOn: 'translationTestObf') { classpath sourceSets.main.runtimeClasspath main 'cuchaz.enigma.CommandMain' args 'deobfuscate', file('build/test-obf/translation.jar'), file('build/test-deobf/translation.jar') } test.dependsOn 'deobfTranslationInput' test { // Since the Minecraft test is really long (like 10 minutes D:) we turn it // off by default. if (!System.getProperty('enableExtremelySlowMinecraftTest', '') .equalsIgnoreCase('true')) { exclude 'cuchaz/enigma/TestSourceIndex.class' } // Allow people to specify a custom path to their Minecraft directory. // (Example: `gradle build -Denigma.test.minecraftdir=./`) systemProperties = [ 'enigma.test.minecraftdir': System.getProperty('test.minecraftdir') ] } // Set the main class. jar.manifest.attributes 'Main-Class': 'cuchaz.enigma.Main' // Make the "fat" application jar. This is useful to just throw in a classpath // for tests, though it includes some slightly useless stuff. shadowJar { append 'LICENSE' append 'README.md' } // Create a library jar, containing only the deobfuscation code, for use at // runtime. This will be deployed to Maven Local with a POM, and can be uploaded // to a remote server manually (for now anyway). task libJar (type: Jar) { classifier = 'lib' from(sourceSets.main.output) { exclude 'cuchaz/enigma/gui/**' exclude 'cuchaz/enigma/convert/**' // Main classes + inner classes (keep CommandMain) exclude 'cuchaz/enigma/Main.class' exclude 'cuchaz/enigma/Main.class' } } task sourcesJar(type: Jar, dependsOn: generateSources) { classifier = 'sources' from generatedSourcesDir from sourceSets.main.resources } publishing { publications { mavenJava(MavenPublication) { from components.java artifact shadowJar artifact libJar artifact sourcesJar } } // select the repositories you want to publish to repositories { if (project.hasProperty('mavenPass')) { maven { url = "http://mavenupload.modmuss50.me/" credentials { username = "buildslave" password = project.getProperty('mavenPass') } } } } }