blob: 13613ae6580e150b21e4130f8dc2b137184aaf94 [file] [log] [blame] [raw]
buildscript {
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
dependencies {
classpath group: 'com.github.HurricaneGamesOrg', name: 'ManualGradleDependencySupplier', version: '1e9e953fb4'
}
}
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.5-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/'
}
}
configurations {
runtimeDependencies
}
dependencies {
Path spigotBuildDirectoryPath = projectBuildDirectoryPath.resolve('spigot')
FileCollection runtimeLibraries = ManualGradleDependencySupplier.supplyDependecies(
projectDirectoryPath.resolve('libraries_runtime'),
[
new BuildDependencySupplier(
'spigot-1.16.5-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.5'],
['spigot-1.16.5.jar']
).setBuildEnv([
'MAVEN_OPTS': '-Dmaven.repo.local=' + spigotBuildDirectoryPath.resolve('m2').toString() + ' -Xmx1024M'
])
],
true
)
FileCollection annotationProcessors = fileTree(dir: projectDirectoryPath.resolve('processors'), include: '*.jar')
runtimeDependencies group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.4-R0.1-SNAPSHOT'
runtimeDependencies annotationProcessors
runtimeDependencies runtimeLibraries
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.4.2'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compileOnly configurations.runtimeDependencies
annotationProcessor annotationProcessors
testImplementation configurations.runtimeDependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
}
compileJava {
doFirst {
classpath -= configurations.runtimeDependencies
classpath += configurations.runtimeDependencies
}
options.encoding = 'UTF-8'
options.incremental = false
options.compilerArgs << ('-Aprotocolsupportbuildprocessor.generatedresourcesdirectory=' + generatedResourcesResourcesDirectoryPath.resolve('preload').toString())
}
test {
Path workingDirectoryPath = projectDirectoryPath.resolve('testsRun');
doFirst {
classpath -= configurations.runtimeDependencies
classpath += configurations.runtimeDependencies
Files.createDirectories(workingDirectoryPath)
}
useJUnitPlatform()
workingDir = workingDirectoryPath;
}
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") })
}}
processResources {
filesMatching('plugin.yml') {
expand 'version': project.version
}
}
shadowJar {
from sourceSets.main.java.srcDirs
from 'LICENSE'
from generatedResourcesDirectoryPath
archiveName = jar.archiveName
exclude 'META-INF/**'
String relocatePrefix = 'protocolsupport.libs.'
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)
test.dependsOn(cleanTest)
compileJava.finalizedBy(test)
jar.enabled = false
jar.finalizedBy(shadowJar)
shadowJar.dependsOn(generateInfo)
shadowJar.dependsOn(generateLocaleList)
shadowJar.finalizedBy(copyFinalJarToTarget)