Files
TCPShield/build.gradle
T

179 lines
4.0 KiB
Groovy

import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import java.nio.charset.StandardCharsets
// --
// Building
// --
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(group: 'org.yaml', name: 'snakeyaml', version: '1.26')
classpath(group: 'com.google.code.gson', name: 'gson', version: '2.8.6')
}
}
plugins {
id 'java'
id 'idea'
}
// --
// Variables
// --
version = '2.5.3'
group = 'net.tcpshield.tcpshield'
archivesBaseName = 'TCPShield'
// --
// Misc.
// --
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
sourceSets {
main {
java {
srcDirs('src/main/java')
}
resources {
srcDirs('src/main/resources')
}
}
test {
java {
srcDirs('src/test/java')
}
resources {
srcDirs('src/test/resources')
}
}
}
compileJava {
sourceCompatibility = "8"
targetCompatibility = "8"
options.encoding = 'UTF-8'
}
// --
// Dependencies
// --
repositories {
maven {
url = 'https://repo1.maven.org/maven2/'
}
maven {
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
url = 'https://repo.dmulloy2.net/nexus/repository/public/'
}
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
maven {
url = 'https://papermc.io/repo/repository/maven-public/'
}
maven {
url = 'https://repo.velocitypowered.com/snapshots/'
}
}
dependencies {
// Bukkit
compileOnly group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
compileOnly group: 'com.comphenix.protocol', name: 'ProtocolLib', version: '4.4.0'
// Paper
compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.15.2-R0.1-SNAPSHOT'
// BungeeCord
compileOnly group: 'net.md-5', name: 'bungeecord-api', version: '1.14-SNAPSHOT'
// Velocity
compileOnly group: 'com.velocitypowered', name: 'velocity-api', version: '1.0.0-SNAPSHOT'
// Testing
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0-M1'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.0-M1'
}
processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
// --
// Build Tasks
// --
test {
useJUnitPlatform()
}
configurations {
testImplementation.extendsFrom compileOnly
}
task updateVersion {
updateYamls()
updateJsons()
}
void updateYamls() {
DumperOptions options = new DumperOptions()
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
options.setSplitLines(false)
options.setPrettyFlow(true)
def yaml = new Yaml(options)
def bukkitYamlFile = new File('src/main/resources/plugin.yml')
def bungeeYamlFile = new File('src/main/resources/bungee.yml')
def files = [bukkitYamlFile, bungeeYamlFile]
files.each { file ->
file.newInputStream().withCloseable { inputStream ->
def cfg = yaml.load(inputStream)
cfg.put("version", version)
new FileWriter(file).withCloseable { writer ->
yaml.dump(cfg, writer)
}
}
}
}
void updateJsons() {
def velocityJson = new File('src/main/resources/velocity-plugin.json')
def files = [velocityJson]
files.each { file ->
file.newInputStream().withCloseable { inputStream ->
new InputStreamReader(inputStream, StandardCharsets.UTF_8).withCloseable { inputStreamReader ->
JsonObject object = JsonParser.parseReader(inputStreamReader).getAsJsonObject()
object.addProperty("version", version.toString())
new FileWriter(file).withCloseable { writer ->
writer.write(object.toString())
}
}
}
}
}
build.dependsOn updateVersion