Plan/Plan/common/build.gradle

168 lines
6.2 KiB
Groovy

import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id "dev.vankka.dependencydownload.plugin" version "$dependencyDownloadVersion"
id "com.github.node-gradle.node" version "3.3.0"
}
configurations {
mysqlDriver
sqliteDriver
testImplementation.extendsFrom mysqlDriver, sqliteDriver
compileOnly.extendsFrom mysqlDriver, sqliteDriver
}
task generateResourceForMySQLDriver(type: GenerateDependencyDownloadResourceTask) {
var conf = configurations.mysqlDriver
configuration = conf
file = "assets/plan/dependencies/" + conf.name + ".txt"
// Not necessary to include in the resource
includeShadowJarRelocations = false
}
task generateResourceForSQLiteDriver(type: GenerateDependencyDownloadResourceTask) {
var conf = configurations.sqliteDriver
configuration = conf
file = "assets/plan/dependencies/" + conf.name + ".txt"
// Not necessary to include in the resource
includeShadowJarRelocations = false
}
dependencies {
implementation "net.playeranalytics:platform-abstraction-layer-api:$palVersion"
implementation project(":api")
compileOnly project(":extensions")
implementation project(path: ":extensions", configuration: 'shadow')
implementation "org.apache.commons:commons-text:$commonsTextVersion"
implementation "org.apache.commons:commons-compress:$commonsCompressVersion"
implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
implementation "com.zaxxer:HikariCP:$hikariVersion"
implementation "org.slf4j:slf4j-nop:$slf4jVersion"
implementation "org.slf4j:slf4j-api:$slf4jVersion"
implementation "com.maxmind.geoip2:geoip2:$geoIpVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
implementation("dev.vankka:dependencydownload-runtime:$dependencyDownloadVersion") {
// Effectively disables relocating
exclude module: "jar-relocator"
}
mysqlDriver "mysql:mysql-connector-java:$mysqlVersion"
sqliteDriver "org.xerial:sqlite-jdbc:$sqliteVersion"
testImplementation project(":api")
testImplementation "com.google.code.gson:gson:$gsonVersion"
testImplementation "org.seleniumhq.selenium:selenium-java:4.2.1"
testImplementation "org.testcontainers:testcontainers:$testContainersVersion"
testImplementation "org.testcontainers:junit-jupiter:$testContainersVersion"
testImplementation "org.testcontainers:nginx:$testContainersVersion"
}
task updateVersion(type: Copy) {
from('src/main/resources') {
include 'plugin.yml'
include 'bungee.yml'
include 'nukkit.yml'
include 'fabric.mod.json'
}
into 'build/sources/resources/'
filter(ReplaceTokens, tokens: [version: '' + project.ext.fullVersion])
}
node {
download = true
version = "16.14.2"
nodeProjectDir = file("$rootDir/react/dashboard")
}
task yarnBundle(type: YarnTask) {
inputs.files(fileTree("$rootDir/react/dashboard/src"))
inputs.file("$rootDir/react/dashboard/package.json")
outputs.dir("$rootDir/react/dashboard/build")
dependsOn yarn_install
args = ['run', 'build']
}
task copyYarnBuildResults {
inputs.files(fileTree("$rootDir/react/dashboard/build"))
outputs.dir("$rootDir/common/build/resources/main/assets/plan/web")
dependsOn yarnBundle
doLast {
mkdir "$rootDir/common/build/resources/main/assets/plan/web"
copy {
from "$rootDir/react/dashboard/build"
into "$rootDir/common/build/resources/main/assets/plan/web"
}
}
}
task determineWebAssetModifications {
doLast {
mkdir "build/resources/main/assets/plan"
def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml")
versionFile.text = "" // Clear previous build
ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web')
tree.forEach { File f ->
def gitModified = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString()
standardOutput = gitModified
}
def gitModifiedAsString = gitModified.toString().strip()
// git returns UNIX time in seconds, but most things in Java use UNIX time in milliseconds
def modified = gitModifiedAsString.isEmpty() ? System.currentTimeMillis() : Long.parseLong(gitModifiedAsString) * 1000
def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree
versionFile.text += String.format( // writing YAML as raw text probably isn't the best idea
"%s: %s\n", relativePath.toString().replace('.', ','), modified
)
}
}
}
processResources {
dependsOn copyYarnBuildResults, determineWebAssetModifications, generateResourceForMySQLDriver, generateResourceForSQLiteDriver
duplicatesStrategy = DuplicatesStrategy.INCLUDE
dependsOn updateVersion
from 'build/sources/resources'
}
shadowJar {
dependsOn processResources
// Exclude these files
exclude "**/*.svg"
exclude "**/*.psd"
exclude "**/module-info.class"
exclude "module-info.class"
exclude 'META-INF/versions/' // Causes Sponge to crash
exclude 'org/apache/http/**/*' // Unnecessary http client depended on by geolite2 implementation
exclude 'mozilla/**/*'
// Exclude unnecessary SQLite drivers
exclude '**/Linux/android-arm/libsqlitejdbc.so'
exclude '**/DragonFlyBSD/**/libsqlitejdbc.so'
relocate 'com.maxmind', 'plan.com.maxmind'
relocate 'com.fasterxml', 'plan.com.fasterxml'
relocate 'com.zaxxer', 'plan.com.zaxxer'
relocate 'com.google.gson', 'plan.com.google.gson'
relocate 'com.google.errorprone', 'plan.com.google.errorprone'
relocate 'org.bstats', 'plan.org.bstats'
relocate 'org.slf4j', 'plan.org.slf4j'
// Exclude test dependencies
exclude "org/junit/**/*"
exclude "org/opentest4j/**/*"
exclude "org/checkerframework/**/*"
exclude "org/apiguardian/**/*"
exclude "org/mockito/**/*"
exclude "org/selenium/**/*"
exclude "org/jayway/**/*"
exclude "google/protobuf/**/*"
exclude "jargs/gnu/**/*"
}