import org.gradle.internal.jvm.Jvm plugins { id 'java' id 'idea' } group = 'intent.zeroday' version = '1.8.9' java { toolchain { languageVersion = JavaLanguageVersion.of(8) } sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } repositories { mavenCentral() maven { name = 'Mojang' url = 'https://libraries.minecraft.net/' } maven { name = 'ViaVersion' url = 'https://repo.viaversion.com/' } } configurations { mcLibs mcNatives shadedDeps clientBundle.extendsFrom(shadedDeps) implementation.extendsFrom(mcLibs, clientBundle) } def java8Compiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(8) } def java8Launcher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(8) } def gradleHostJavaExe = Jvm.current().javaExecutable.absolutePath def mcefJar = file('libs/mcef-1.8.9.jar') def authProvidersJar = file('libs/auth-providers.jar') def flacEncoderJar = file('libs/java-flac-encoder.jar') def jfxCompileStubsJar = file('libs/javafx8-compile-stubs.jar') // Resolve jfxrt.jar and nashorn.jar from Java 8 Toolchain or local JDK 8 installations when available def resolveJava8ExtJars = { def found = [] def homes = [java8Launcher.get().metadata.installationPath.asFile] def userJdks = new File(System.getProperty('user.home', '.'), '.jdks') if (userJdks.isDirectory()) { userJdks.listFiles()?.findAll { it.isDirectory() && it.name.contains('1.8') }?.each { homes << it } } for (String extName : ['nashorn.jar', 'jfxrt.jar']) { for (File h : homes) { def c1 = new File(h, "jre/lib/ext/${extName}") def c2 = new File(h, "lib/ext/${extName}") if (c1.isFile()) { found << c1; break } if (c2.isFile()) { found << c2; break } } } return files(found) } dependencies { implementation files({ resolveJava8ExtJars() }) compileOnly files(jfxCompileStubsJar) // Modular native, audio & auth third-party libraries shadedDeps files(mcefJar, authProvidersJar, flacEncoderJar) // Standard open-source libraries via Maven Central & ViaVersion Maven shadedDeps('com.viaversion:viaversion:4.3.1') { transitive = false } shadedDeps('com.viaversion:viabackwards-common:4.3.1') { transitive = false } shadedDeps('com.viaversion:viarewind-core:2.0.1') { transitive = false } shadedDeps('org.yaml:snakeyaml:1.26') { transitive = false } shadedDeps('com.google.code.findbugs:jsr305:3.0.2') { transitive = false } // ZeroDay custom Maven Central libraries (from Zeroday.json) clientBundle 'javax.vecmath:vecmath:1.5.2' clientBundle 'net.sf.trove4j:trove4j:3.0.3' clientBundle 'org.eclipse.jetty:jetty-io:9.4.35.v20201120' clientBundle 'org.eclipse.jetty:jetty-http:9.4.35.v20201120' clientBundle 'org.eclipse.jetty:jetty-util:9.4.35.v20201120' clientBundle 'org.eclipse.jetty:jetty-server:9.4.35.v20201120' clientBundle 'org.eclipse.jetty:jetty-servlet:9.4.35.v20201120' clientBundle 'it.unimi.dsi:fastutil:8.2.1' clientBundle 'javazoom:jlayer:1.0.1' clientBundle 'javax.servlet:javax.servlet-api:3.1.0' clientBundle('org.slick2d:slick2d-core:1.0.0') { transitive = false } // Minecraft 1.8.9 & Netty libraries (from Zeroday.json via Mojang Maven & Maven Central) mcLibs 'oshi-project:oshi-core:1.1' mcLibs 'net.java.dev.jna:jna:3.4.0' mcLibs 'net.java.dev.jna:platform:3.4.0' mcLibs 'com.ibm.icu:icu4j-core-mojang:51.2' mcLibs 'net.sf.jopt-simple:jopt-simple:4.6' mcLibs 'com.paulscode:codecjorbis:20101023' mcLibs 'com.paulscode:codecwav:20101023' mcLibs 'com.paulscode:libraryjavasound:20101123' mcLibs 'com.paulscode:librarylwjglopenal:20100824' mcLibs 'com.paulscode:soundsystem:20120107' mcLibs 'io.netty:netty-all:4.1.42.Final' mcLibs 'com.google.guava:guava:17.0' mcLibs 'org.apache.commons:commons-lang3:3.3.2' mcLibs 'commons-io:commons-io:2.4' mcLibs 'commons-codec:commons-codec:1.9' mcLibs 'net.java.jinput:jinput:2.0.5' mcLibs 'net.java.jutils:jutils:1.0.0' mcLibs 'com.google.code.gson:gson:2.2.4' mcLibs 'com.mojang:authlib:1.5.21' mcLibs 'com.mojang:realms:1.7.59' mcLibs 'org.apache.commons:commons-compress:1.8.1' mcLibs 'org.apache.httpcomponents:httpclient:4.3.3' mcLibs 'commons-logging:commons-logging:1.1.3' mcLibs 'org.apache.httpcomponents:httpcore:4.3.2' mcLibs 'org.apache.logging.log4j:log4j-api:2.0-beta9' mcLibs 'org.apache.logging.log4j:log4j-core:2.0-beta9' mcLibs('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209') { transitive = false } mcLibs('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209') { transitive = false } mcLibs('tv.twitch:twitch:6.5') { transitive = false } // Platform native libraries for LWJGL / OpenAL / JInput / Twitch def osName = System.getProperty('os.name', '').toLowerCase(Locale.ROOT) if (osName.contains('win')) { mcNatives 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209:natives-windows' mcNatives 'net.java.jinput:jinput-platform:2.0.5:natives-windows' mcNatives 'tv.twitch:twitch-platform:6.5:natives-windows-64' mcNatives 'tv.twitch:twitch-external-platform:4.5:natives-windows-64' } else if (osName.contains('mac')) { mcNatives 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209:natives-osx' mcNatives 'net.java.jinput:jinput-platform:2.0.5:natives-osx' mcNatives 'tv.twitch:twitch-platform:6.5:natives-osx' } else { mcNatives 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209:natives-linux' mcNatives 'net.java.jinput:jinput-platform:2.0.5:natives-linux' } } idea { module { downloadJavadoc = false downloadSources = false scopes.COMPILE.plus += [configurations.compileClasspath] } } def emptySourceDir = layout.buildDirectory.dir('tmp/empty-sourcepath').get().asFile tasks.named('compileJava', JavaCompile) { javaCompiler.set(java8Compiler) options.encoding = 'UTF-8' options.fork = true options.forkOptions.memoryMaximumSize = '2048m' doFirst { emptySourceDir.mkdirs() } options.sourcepath = files(emptySourceDir) options.compilerArgs.addAll(['-XDignore.symbol.file', '-Xlint:-options,-varargs,-deprecation,-unchecked', '-proc:none', '-implicit:none']) } tasks.register('clientJar', Exec) { group = 'build' description = 'Builds standalone zeroday-1.8.9-runtime.jar from compiled Java sources + resources + shaded runtime dependencies.' dependsOn 'classes', configurations.shadedDeps def outClassesDir = sourceSets.main.java.destinationDirectory.get().asFile def resourcesDir = file('src/main/resources') def runtimeOut = layout.buildDirectory.file('libs/zeroday-1.8.9-runtime.jar').get().asFile doFirst { def bundlePath = configurations.shadedDeps.asPath commandLine( gradleHostJavaExe, '-Xmx1024m', file('tools/BuildStandaloneClientJar.java').absolutePath, outClassesDir.absolutePath, resourcesDir.absolutePath, bundlePath, runtimeOut.absolutePath ) } } tasks.named('assemble') { dependsOn 'clientJar' } def extractedNativesDir = layout.buildDirectory.dir('natives') tasks.register('extractNatives', Sync) { description = 'Extracts platform LWJGL/OpenAL/JInput/Twitch native libraries from Mojang Maven.' dependsOn configurations.mcNatives from { configurations.mcNatives.collect { zipTree(it) } } exclude 'META-INF/**' into extractedNativesDir } def resolveDefaultMcAssetsDir = { def custom = findProperty('mcAssetsDir') if (custom != null) return file(custom) def osName = System.getProperty('os.name', '').toLowerCase(Locale.ROOT) def home = System.getProperty('user.home', '.') File cand if (osName.contains('win')) { def appData = System.getenv('APPDATA') ?: new File(home, 'AppData/Roaming').absolutePath cand = new File(appData, '.minecraft/assets') } else if (osName.contains('mac')) { cand = new File(home, 'Library/Application Support/minecraft/assets') } else { cand = new File(home, '.minecraft/assets') } return cand.isDirectory() ? cand : file('run/assets') } tasks.register('runClient', JavaExec) { group = 'application' description = 'Builds zeroday-1.8.9-runtime.jar from Java 8 source and launches ZeroDay (1.8.9) under Java 8.' dependsOn 'clientJar', 'extractNatives', configurations.mcLibs, configurations.clientBundle javaLauncher.set(java8Launcher) def runtimeOut = layout.buildDirectory.file('libs/zeroday-1.8.9-runtime.jar').get().asFile def runDir = file('run') workingDir = runDir maxHeapSize = '2G' mainClass = 'net.minecraft.client.main.Main' classpath = files(runtimeOut, { resolveJava8ExtJars() }, configurations.clientBundle, configurations.mcLibs) doFirst { runDir.mkdirs() def assetsDir = resolveDefaultMcAssetsDir() assetsDir.mkdirs() jvmArgs( "-Djava.library.path=${extractedNativesDir.get().asFile.absolutePath}", '-Dlog4j2.formatMsgNoLookups=true' ) args( '--username', 'Player', '--version', 'Zeroday', '--accessToken', '0', '--assetsDir', assetsDir.absolutePath, '--assetIndex', '1.8', '--userProperties', '{}', '--userType', 'mojang', '--gameDir', runDir.absolutePath ) } }