Plan/Plan/common/build.gradle

253 lines
9.9 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 "7.0.2"
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.2.21"
}
configurations {
// Runtime downloading scopes
mysqlDriver
mariadbDriver
sqliteDriver
ipAddressMatcher
testImplementation.extendsFrom mysqlDriver, mariadbDriver, sqliteDriver, ipAddressMatcher
compileOnly.extendsFrom mysqlDriver, mariadbDriver, sqliteDriver, ipAddressMatcher
swaggerJson // swagger.json configuration
}
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 generateResourceForMariaDBDriver(type: GenerateDependencyDownloadResourceTask) {
var conf = configurations.mariadbDriver
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
}
task generateResourceForIpAddressMatcher(type: GenerateDependencyDownloadResourceTask) {
var conf = configurations.ipAddressMatcher
configuration = conf
file = "assets/plan/dependencies/" + conf.name + ".txt"
// Not necessary to include in the resource
includeShadowJarRelocations = false
}
dependencies {
implementation project(":api")
shadow project(":extensions")
shadow "net.playeranalytics:platform-abstraction-layer-api:$palVersion"
compileOnly "net.kyori:adventure-api:4.14.0"
shadow("dev.vankka:dependencydownload-runtime:$dependencyDownloadVersion") {
// Effectively disables relocating
exclude module: "jar-relocator"
}
mysqlDriver "com.mysql:mysql-connector-j:$mysqlVersion"
mariadbDriver "org.mariadb.jdbc:mariadb-java-client:$mariadbVersion"
sqliteDriver "org.xerial:sqlite-jdbc:$sqliteVersion"
sqliteDriver "org.slf4j:slf4j-nop:1.7.36"
ipAddressMatcher "com.github.seancfoley:ipaddress:$ipAddressMatcherVersion"
shadow "org.apache.commons:commons-text:$commonsTextVersion"
shadow "org.apache.commons:commons-compress:$commonsCompressVersion"
shadow "commons-codec:commons-codec:$commonsCodecVersion"
shadow "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
shadow "com.zaxxer:HikariCP:$hikariVersion"
shadow "org.slf4j:slf4j-nop:$slf4jVersion"
shadow "org.slf4j:slf4j-api:$slf4jVersion"
shadow "com.maxmind.geoip2:geoip2:$geoIpVersion"
shadow "com.google.code.gson:gson:$gsonVersion"
shadow "org.eclipse.jetty:jetty-server:$jettyVersion"
shadow "org.eclipse.jetty:jetty-alpn-java-server:$jettyVersion"
shadow "org.eclipse.jetty.http2:http2-server:$jettyVersion"
shadow("com.googlecode.json-simple:json-simple:1.1.1") { // json simple used by UUIDFetcher
// json-simple has junit (a test dependency) compile scoped
exclude group: "junit", module: "junit"
}
implementation "org.jasypt:jasypt:$jasyptVersion:lite"
// Swagger annotations
implementation "jakarta.ws.rs:jakarta.ws.rs-api:3.1.0"
implementation "io.swagger.core.v3:swagger-core-jakarta:$swaggerVersion"
implementation "io.swagger.core.v3:swagger-jaxrs2-jakarta:$swaggerVersion"
testImplementation project(":api")
testArtifacts project(":extensions:adventure")
testImplementation project(":extensions:adventure")
testImplementation "com.google.code.gson:gson:$gsonVersion"
testImplementation "org.seleniumhq.selenium:selenium-java:4.19.0"
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 = "20.9.0"
nodeProjectDir = file("$rootDir/react/dashboard")
}
task yarnBundle(type: YarnTask) {
inputs.files(fileTree("$rootDir/react/dashboard/src"))
inputs.file("$rootDir/react/dashboard/package.json")
inputs.file("$rootDir/react/dashboard/vite.config.js")
outputs.dir("$rootDir/react/dashboard/build")
dependsOn yarn_install
args = ['run', 'build']
}
task yarnStart(type: YarnTask) {
logging.captureStandardOutput LogLevel.INFO
inputs.file("$rootDir/react/dashboard/package.json")
dependsOn yarn_install
args = ['run', 'start']
}
task copyYarnBuildResults {
inputs.files(fileTree("$rootDir/react/dashboard/build"))
outputs.dir("$rootDir/common/build/resources/main/assets/plan/web")
outputs.dir("$rootDir/common/build/resources/test/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"
}
copy {
into "$rootDir/common/build/resources/main/assets/plan/web"
into "$rootDir/common/build/resources/test/assets/plan/web"
}
}
}
task determineAssetModifications {
dependsOn yarnBundle
inputs.files(fileTree("$rootDir/react/dashboard/build"))
inputs.files(fileTree(dir: 'src/main/resources/assets/plan/web'))
inputs.files(fileTree(dir: 'src/main/resources/assets/plan/locale'))
outputs.file("build/resources/main/assets/plan/AssetVersion.yml")
doLast {
mkdir "build/resources/main/assets/plan"
def versionFile = file("build/resources/main/assets/plan/AssetVersion.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(
"%s: %s\n", relativePath.toString().replace('.', ',').replace('\\', '/'), modified
)
}
tree = fileTree(dir: 'src/main/resources/assets/plan/locale')
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(
"%s: %s\n", relativePath.toString().replace('.', ',').replace('\\', '/'), modified
)
}
tree = fileTree("$rootDir/react/dashboard/build")
tree.forEach { File f ->
if (f.getName().endsWith(".map")) return
def modified = System.currentTimeMillis()
def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree
versionFile.text += String.format(
"%s: %s\n", relativePath.toString().replace('.', ',').replace('\\', '/'), modified
)
}
}
}
resolve { // Swagger json generation task
outputFileName = 'swagger'
outputFormat = 'JSON'
prettyPrint = 'TRUE'
classpath = sourceSets.main.runtimeClasspath
buildClasspath = classpath
resourcePackages = [
'com.djrapitops.plan.delivery.webserver',
'com.djrapitops.plan.delivery.webserver.resolver.auth',
'com.djrapitops.plan.delivery.webserver.resolver.json',
]
outputDir = file('build/generated-resources/swagger/assets/plan/web/')
}
task swaggerJsonJar(type: Jar) {
dependsOn resolve
archiveClassifier.set("resolve")
from 'build/generated-resources/swagger'
}
artifacts {
swaggerJson swaggerJsonJar
}
processResources {
// Skips Yarn build on Jitpack since Jitpack doesn't offer gclib version compatible with Node 20
// Jitpack build is used mainly for java dependencies.
if (!project.hasProperty("isJitpack")) {
dependsOn copyYarnBuildResults
dependsOn determineAssetModifications
}
dependsOn generateResourceForMySQLDriver
dependsOn generateResourceForSQLiteDriver
dependsOn generateResourceForIpAddressMatcher
dependsOn updateVersion
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from 'build/sources/resources'
}
shadowJar {
configurations = [project.configurations.shadow]
}