blob: 4cd7335781325396f18bfce7c281a6b3e94c7af0 [file] [log] [blame] [raw]
buildscript {
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
dependencies {
classpath group: 'com.github.HurricaneGamesOrg', name: 'ManualGradleDependencySupplier', version: '4f4893da88'
}
}
plugins {
id 'java'
id 'maven'
id 'com.github.johnrengelman.shadow' version '5.0.0'
}
apply plugin: 'org.hurricanegames.ManualGradleDependencySupplier'
defaultTasks 'build'
group 'protocolsupport'
version '1.16.2-2-dev'
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
import org.hurricanegames.manualgradledependencysupplier.DependencySupplier
import org.hurricanegames.manualgradledependencysupplier.BuildDependencySupplier
import org.hurricanegames.manualgradledependencysupplier.ManualGradleDependencySupplier
Path projectDirectoryPath = projectDir.toPath().toAbsolutePath()
Path projectBuildDirectoryPath = getBuildDir().toPath()
Path generatedResourcesDirectoryPath = projectDirectoryPath.resolve('gen')
String resourcesDirectoryName = 'resources';
Path generatedResourcesResourcesDirectoryPath = generatedResourcesDirectoryPath.resolve(resourcesDirectoryName)
task setupFolders(type: DefaultTask) {doLast{
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/'
}
}
dependencies {
Path spigotBuildDirectoryPath = projectBuildDirectoryPath.resolve('spigot')
FileCollection runtimeLibraries = ManualGradleDependencySupplier.supplyDependecies(
projectDirectoryPath.resolve('libraries_runtime'),
[
new BuildDependencySupplier(
'spigot-1.16.2-1.jar',
new URL('https://hub.spigotmc.org/jenkins/job/BuildTools/120/artifact/target/BuildTools.jar'),
spigotBuildDirectoryPath,
'BuildTools.jar',
['java', '-jar', 'BuildTools.jar', '--rev', '1.16.2'],
['spigot-1.16.2.jar']
).setBuildEnv([
"MAVEN_OPTS": "-Dmaven.repo.local=" + spigotBuildDirectoryPath.resolve("m2").toString() + " -Xmx1024M"
])
],
true
)
FileCollection annotationProcessors = fileTree(dir: projectDirectoryPath.resolve('processors'), include: '*.jar')
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'
compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.2-R0.1-SNAPSHOT'
compileOnly annotationProcessors
compileOnly runtimeLibraries
annotationProcessor annotationProcessors
testCompile group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.2-R0.1-SNAPSHOT'
testCompile runtimeLibraries
testCompile annotationProcessors
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
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)
Files.copy(
shadowJar.archivePath.toPath().toAbsolutePath(),
targetJarDirectory.resolve(shadowJar.baseName + '.jar'),
java.nio.file.StandardCopyOption.REPLACE_EXISTING
)
}}
compileJava.dependsOn(clean)
compileJava.dependsOn(setupFolders)
compileJava.finalizedBy(test)
jar.enabled = false
jar.finalizedBy(shadowJar)
shadowJar.dependsOn(generateInfo)
shadowJar.dependsOn(generateLocaleList)
shadowJar.finalizedBy(copyFinalJarToTarget)