| import java.nio.file.Path |
| import java.nio.file.Paths |
| import java.nio.file.Files |
| |
| plugins { |
| id 'com.github.johnrengelman.shadow' version '5.0.0' |
| id 'java' |
| } |
| |
| apply from: 'gradle/helper.gradle' |
| |
| |
| defaultTasks 'build' |
| |
| |
| group 'protocolsupport' |
| version '4.29-dev' |
| |
| |
| Path projectDirectoryPath = projectDir.toPath().toAbsolutePath() |
| |
| |
| Path librariesRuntimeDirectoryPath = projectDirectoryPath.resolve("libraries_runtime") |
| Path librariesShadeDirectoryPath = projectDirectoryPath.resolve("libraries_shade") |
| Path annotationProcessorsDirectoryPath = projectDirectoryPath.resolve("processors") |
| Path generatedResourcesDirectoryPath = projectDirectoryPath.resolve("gen") |
| String resourcesDirectoryName = "resources"; |
| Path generatedResourcesResourcesDirectoryPath = generatedResourcesDirectoryPath.resolve(resourcesDirectoryName) |
| |
| task setupFolders(type: DefaultTask) {doLast{ |
| Files.createDirectories(librariesRuntimeDirectoryPath) |
| Files.createDirectories(librariesShadeDirectoryPath) |
| Files.createDirectories(annotationProcessorsDirectoryPath) |
| generatedResourcesDirectoryPath.toFile().deleteDir() |
| Files.createDirectories(generatedResourcesDirectoryPath) |
| Files.createDirectories(generatedResourcesResourcesDirectoryPath) |
| }} |
| |
| |
| sourceCompatibility = JavaVersion.VERSION_1_8 |
| |
| sourceSets { |
| main { |
| java { |
| srcDirs = ['src'] |
| } |
| resources { |
| srcDirs = ['resources'] |
| } |
| } |
| test { |
| java { |
| srcDirs = ['tests'] |
| } |
| } |
| } |
| |
| repositories { |
| mavenCentral() |
| jcenter() |
| maven { |
| url 'https://oss.sonatype.org/content/repositories/snapshots/' |
| } |
| maven { |
| url 'https://papermc.io/repo/repository/maven-public/' |
| } |
| } |
| |
| task updateSpigot(type: BuildLibraryTask) { |
| targetDirectory = librariesRuntimeDirectoryPath |
| targetLibraryName = "spigot-1.16.2-1.jar" |
| builderUrl = "https://hub.spigotmc.org/jenkins/job/BuildTools/120/artifact/target/BuildTools.jar" |
| buildCommand = "java -jar {BUILDER} --rev 1.16.2" |
| builtLibraryName = ["spigot-1.16.2.jar"] |
| } |
| |
| task updateRuntimeLibraries(type: UpdateLibrariesTask) { |
| directory = librariesRuntimeDirectoryPath |
| libraries = [] |
| manualLibraries = new HashSet<>(Arrays.asList(updateSpigot.targetLibraryName)) |
| } |
| |
| task updateShadeLibraries(type: UpdateLibrariesTask) { |
| directory = librariesShadeDirectoryPath |
| 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: librariesShadeDirectoryPath, include: '*.jar') |
| compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.2-R0.1-SNAPSHOT' |
| compileOnly fileTree(dir: librariesRuntimeDirectoryPath, include: '*.jar') |
| |
| annotationProcessor fileTree(dir: annotationProcessorsDirectoryPath, include: '*.jar') |
| compileOnly fileTree(dir: annotationProcessorsDirectoryPath, include: '*.jar') |
| |
| testCompile group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.2-R0.1-SNAPSHOT' |
| testCompile fileTree(dir: librariesRuntimeDirectoryPath, include: '*.jar') |
| testCompile fileTree(dir: annotationProcessorsDirectoryPath, 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.compileOnly |
| classpath += configurations.compileOnly |
| } |
| |
| options.encoding = 'UTF-8' |
| options.incremental = false |
| options.compilerArgs << ("-Aprotocolsupportbuildprocessor.generatedresourcesdirectory=" + generatedResourcesResourcesDirectoryPath.resolve("preload").toString()) |
| } |
| |
| |
| test { |
| useJUnitPlatform() |
| } |
| |
| |
| task generateLocaleList(type: DefaultTask) {doLast{ |
| Path i18nDirectory = generatedResourcesResourcesDirectoryPath.resolve("i18n") |
| Files.createDirectories(i18nDirectory) |
| new PrintWriter(Files.newBufferedWriter(i18nDirectory.resolve("languages"))).withCloseable({ |
| writer -> |
| Files.list(sourceSets.main.resources.srcDirs[0].toPath().resolve(resourcesDirectoryName).resolve("i18n")) |
| .forEach({ |
| String[] split = it.getFileName().toString().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")) |
| Files.newBufferedWriter(generatedResourcesResourcesDirectoryPath.resolve("buildinfo")).withCloseable({ properties.store(it, "Build info") }) |
| }} |
| |
| String relocatePrefix = "protocolsupport.libs." |
| |
| shadowJar { |
| from sourceSets.main.java.srcDirs |
| from 'LICENSE' |
| from generatedResourcesDirectoryPath.toFile() |
| |
| archiveName = jar.archiveName |
| |
| exclude 'META-INF/**' |
| relocate 'org.apache', relocatePrefix + 'org.apache' |
| relocate 'it.unimi.dsi.fastutil', relocatePrefix + 'it.unimi.dsi.fastutil' |
| relocate 'com.google.gson', relocatePrefix + 'com.google.gson' |
| |
| minimize() |
| } |
| |
| |
| task copyFinalJarToTarget(type: DefaultTask) {doLast{ |
| Path targetJarDirectory = projectDirectoryPath.resolve("target") |
| Files.createDirectories(targetJarDirectory) |
| java.nio.file.Files.copy( |
| shadowJar.archivePath.toPath().toAbsolutePath(), |
| targetJarDirectory.resolve(jar.baseName + '.jar'), |
| 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(copyFinalJarToTarget) |