| plugins { |
| id 'com.github.johnrengelman.shadow' version '5.0.0' |
| id 'java' |
| } |
| |
| apply from: 'helper.gradle' |
| |
| |
| defaultTasks 'build' |
| |
| |
| group 'protocolsupport' |
| version '4.29-dev' |
| |
| |
| File librariesRuntimeDirectory = new File("libraries_runtime") |
| File librariesShadeDirectory = new File("libraries_shade") |
| File generatedResourcesDirectory = new File("gen") |
| File annotationProcessorsDirectory = new File("processors") |
| File targetJarDirectory = new File("target") |
| String resourcesDirectoryName = "resources"; |
| |
| task setupFolders(type: DefaultTask) {doLast{ |
| librariesRuntimeDirectory.mkdirs() |
| librariesShadeDirectory.mkdirs() |
| targetJarDirectory.mkdirs() |
| generatedResourcesDirectory.deleteDir() |
| generatedResourcesDirectory.mkdirs() |
| }} |
| |
| |
| sourceCompatibility = JavaVersion.VERSION_1_8 |
| |
| sourceSets { |
| main { |
| java { |
| srcDirs = ['src'] |
| } |
| resources { |
| srcDirs = ['resources'] |
| } |
| } |
| test { |
| java { |
| srcDirs = ['tests'] |
| } |
| } |
| } |
| |
| repositories { |
| mavenCentral() |
| jcenter() |
| maven { |
| url 'https://papermc.io/repo/repository/maven-public/' |
| } |
| } |
| |
| task updateSpigot(type: BuildLibraryTask) { |
| targetDirectory = librariesRuntimeDirectory |
| targetLibraryName = "spigot-1.15.2-1.jar" |
| builderUrl = "https://papermc.io/api/v1/paper/1.15.2/65/download" |
| buildCommand = "java -Dpaperclip.patchonly=true -jar {BUILDER}" |
| builtLibraryName = ["cache", "patched_1.15.2.jar"] |
| } |
| |
| task updateRuntimeLibraries(type: UpdateLibrariesTask) { |
| directory = librariesRuntimeDirectory |
| libraries = [] |
| manualLibraries = new HashSet<>(Arrays.asList(updateSpigot.targetLibraryName)) |
| } |
| |
| task updateShadeLibraries(type: UpdateLibrariesTask) { |
| directory = librariesShadeDirectory |
| libraries = [] |
| } |
| |
| dependencies { |
| compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' |
| compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2' |
| compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' |
| compile fileTree(dir: librariesShadeDirectory, include: '*.jar') |
| shadow group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.15.1-R0.1-SNAPSHOT' |
| shadow fileTree(dir: librariesRuntimeDirectory, include: '*.jar') |
| shadow fileTree(dir: new File("libraries_runtime_manual"), include: '*.jar') |
| |
| annotationProcessor fileTree(dir: annotationProcessorsDirectory, include: '*.jar') |
| shadow fileTree(dir: annotationProcessorsDirectory, include: '*.jar') |
| |
| testCompile fileTree(dir: librariesRuntimeDirectory, include: '*.jar') |
| testCompile fileTree(dir: librariesShadeDirectory, include: '*.jar') |
| testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0' |
| testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0' |
| } |
| |
| compileJava { |
| doFirst { |
| classpath -= configurations.shadow |
| classpath += configurations.shadow |
| } |
| |
| options.encoding = 'UTF-8' |
| options.incremental = false |
| options.compilerArgs << ("-Aprotocolsupportbuildprocessor.generatedresourcesdirectory=" + newFile(generatedResourcesDirectory, resourcesDirectoryName, "preload").getAbsolutePath()) |
| } |
| |
| |
| test { |
| useJUnitPlatform() |
| } |
| |
| |
| task generateLocaleList(type: DefaultTask) {doLast{ |
| File langsListFile = newFile(generatedResourcesDirectory, resourcesDirectoryName, "i18n", "languages") |
| langsListFile.getParentFile().mkdirs() |
| langsListFile.createNewFile() |
| new PrintWriter(langsListFile).withCloseable({ |
| writer -> |
| newFile(sourceSets.main.resources.srcDirs.iterator().next(), resourcesDirectoryName, "i18n").list() |
| .each({ |
| String[] split = it.split("[.]"); |
| if (split.length == 2 && split[1].equals("json")) { |
| writer.println(split[0]) |
| } |
| }) |
| }) |
| }} |
| |
| task generateInfo(type: DefaultTask) {doLast{ |
| Properties properties = new Properties() |
| properties.setProperty("buildtime", new Date().format("yyyy.MM.dd 'at' HH:mm:ss z")) |
| properties.setProperty("buildhost", System.getProperty("protocolsupport.buildhost", "unknown")) |
| properties.setProperty("buildnumber", System.getProperty("protocolsupport.buildnumber", "unknown")) |
| properties.setProperty("buildgit", System.getProperty("protocolsupport.buildgit", "unknown")) |
| File buildInfoFile = newFile(generatedResourcesDirectory, resourcesDirectoryName, "buildinfo") |
| buildInfoFile.getParentFile().mkdirs() |
| buildInfoFile.createNewFile() |
| new FileOutputStream(buildInfoFile).withCloseable({ properties.store(it, "Build info") }) |
| }} |
| |
| shadowJar { |
| doFirst { |
| new File(destinationDir, archiveName).delete() |
| } |
| |
| from sourceSets.main.java.srcDirs |
| from 'LICENSE' |
| from generatedResourcesDirectory |
| |
| archiveName = jar.archiveName |
| |
| exclude 'META-INF/**' |
| relocate 'org.apache', 'protocolsupport.libs.org.apache' |
| relocate 'it.unimi.dsi.fastutil', 'protocolsupport.libs.it.unimi.dsi.fastutil' |
| relocate 'com.google.gson', 'protocolsupport.libs.com.google.gson' |
| |
| minimize() |
| } |
| |
| |
| task postprocessFatJar(type: Zip) { |
| Set<String> workaroundRelocationClasses = new HashSet<>(Arrays.asList( |
| "protocolsupport/zplatform/impl/spigot/entitytracker/SpigotEntityTrackerEntryInjectorMap.class", |
| "protocolsupport/zplatform/impl/spigot/entitytracker/PaperSpigotEntityTrackerEntryInjectorMap.class", |
| "protocolsupport/zplatform/impl/spigot/injector/SpigotEntityTrackerInjector.class" |
| )); |
| File originalJar = new File(shadowJar.destinationDir, shadowJar.archiveName) |
| |
| archiveName = shadowJar.archiveName |
| |
| from(zipTree(originalJar)) { |
| exclude(workaroundRelocationClasses) |
| exclude 'META-INF/**' |
| } |
| |
| from(sourceSets.main.output.classesDirs) { |
| include(workaroundRelocationClasses) |
| } |
| } |
| |
| |
| task copyFinalJarToTarget(type: DefaultTask) {doLast{ |
| java.nio.file.Files.copy( |
| postprocessFatJar.archivePath.getAbsoluteFile().toPath(), |
| new File(targetJarDirectory, jar.baseName + '.jar').getAbsoluteFile().toPath(), |
| java.nio.file.StandardCopyOption.REPLACE_EXISTING |
| ) |
| }} |
| |
| |
| compileJava.dependsOn(clean) |
| compileJava.dependsOn(setupFolders) |
| compileJava.dependsOn(updateSpigot) |
| compileJava.dependsOn(updateRuntimeLibraries) |
| compileJava.dependsOn(updateShadeLibraries) |
| compileJava.finalizedBy(test) |
| jar.enabled = false |
| jar.finalizedBy(shadowJar) |
| shadowJar.dependsOn(generateInfo) |
| shadowJar.dependsOn(generateLocaleList) |
| shadowJar.finalizedBy(postprocessFatJar) |
| postprocessFatJar.finalizedBy(copyFinalJarToTarget) |