Clean up build scripts using new Gradle features (#2436)

* Make use of `TYPESAFE_PROJECT_ACCESSORS` and `VERSION_CATALOGS` Gradle feature previews to clean up build scripts

* Bump setup-java action to v2, specify AdoptOpenJDK distribution
This commit is contained in:
Jason 2021-04-14 05:16:48 -07:00 committed by GitHub
parent c7e5b4a297
commit 87d54f1103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 154 additions and 112 deletions

View File

@ -13,8 +13,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v1 uses: actions/setup-java@v2
with: with:
distribution: 'adopt'
java-version: 11 java-version: 11
- name: Build with Gradle - name: Build with Gradle
run: ./gradlew build run: ./gradlew build

View File

@ -1,9 +1,11 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
plugins {
id("com.github.johnrengelman.shadow")
}
// Shade and relocate adventure in an extra module, so that common/the rest can directly depend on a // Shade and relocate adventure in an extra module, so that common/the rest can directly depend on a
// relocated adventure without breaking native platform's adventure usage with project wide relocation // relocated adventure without breaking native platform's adventure usage with project wide relocation
apply<ShadowPlugin>()
tasks { tasks {
withType<ShadowJar> { withType<ShadowJar> {
relocate("net.kyori", "us.myles.viaversion.libs.kyori") relocate("net.kyori", "us.myles.viaversion.libs.kyori")
@ -14,16 +16,10 @@ tasks {
} }
dependencies { dependencies {
api("net.kyori", "adventure-api", Versions.adventure) { api(libs.bundles.adventure) {
exclude("org.checkerframework") exclude("org.checkerframework")
}
api("net.kyori", "adventure-text-serializer-gson", Versions.adventure) {
exclude("net.kyori", "adventure-api") exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom") exclude("net.kyori", "adventure-bom")
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")
} }
api("net.kyori", "adventure-text-serializer-legacy", Versions.adventure) {
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
}
} }

View File

@ -1,5 +1,5 @@
plugins { plugins {
id("net.kyori.blossom") version "1.2.0" id("net.kyori.blossom")
} }
blossom { blossom {
@ -8,13 +8,15 @@ blossom {
} }
dependencies { dependencies {
api(project(":adventure", "shadow")) api(projects.adventure) {
api("it.unimi.dsi", "fastutil", Versions.fastUtil) targetConfiguration = "shadow"
api("com.viaversion", "opennbt", Versions.openNBT) }
api("com.google.code.gson", "gson", Versions.gson) api(libs.fastutil)
api(libs.openNBT)
api(libs.gson)
compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml) compileOnlyApi(libs.snakeYaml)
compileOnlyApi("io.netty", "netty-all", Versions.netty) compileOnlyApi(libs.netty)
compileOnlyApi("com.google.guava", "guava", Versions.guava) compileOnlyApi(libs.guava)
compileOnlyApi("org.checkerframework", "checker-qual", Versions.checkerQual) compileOnlyApi(libs.checkerQual)
} }

View File

@ -3,6 +3,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
plugins { plugins {
`java-library` `java-library`
`maven-publish` `maven-publish`
id("net.kyori.blossom") version "1.2.0" apply false
} }
allprojects { allprojects {
@ -31,21 +32,6 @@ subprojects {
} }
} }
val platforms = listOf(
"bukkit",
"bungee",
"fabric",
"sponge",
"velocity"
).map { "viaversion-$it" }
if (platforms.contains(project.name)) {
configureShadowJar()
} else if (project.name == "viaversion-api") {
configureShadowJarAPI()
} else if (project.name == "viaversion") {
apply<ShadowPlugin>()
}
repositories { repositories {
maven("https://repo.viaversion.com") maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/") maven("https://papermc.io/repo/repository/maven-public/")
@ -53,20 +39,18 @@ subprojects {
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/") maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
maven("https://repo.spongepowered.org/repository/maven-public/") maven("https://repo.spongepowered.org/repository/maven-public/")
maven("https://libraries.minecraft.net") maven("https://libraries.minecraft.net")
maven("https://repo.maven.apache.org/maven2/") mavenCentral()
} }
dependencies { dependencies {
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA' // Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
testImplementation("io.netty", "netty-all", Versions.netty) testImplementation(rootProject.libs.netty)
testImplementation("com.google.guava", "guava", Versions.guava) testImplementation(rootProject.libs.guava)
testImplementation("org.junit.jupiter", "junit-jupiter-api", Versions.jUnit) testImplementation(rootProject.libs.bundles.junit)
testImplementation("org.junit.jupiter", "junit-jupiter-engine", Versions.jUnit)
} }
configureJavaTarget(8)
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar() withSourcesJar()
withJavadocJar() withJavadocJar()
} }
@ -96,6 +80,18 @@ subprojects {
} }
} }
sequenceOf(
projects.viaversionBukkit,
projects.viaversionBungee,
projects.viaversionFabric,
projects.viaversionSponge,
projects.viaversionVelocity
).map { it.dependencyProject }.forEach { project ->
project.configureShadowJar()
}
projects.viaversionApi.dependencyProject.configureShadowJarAPI()
tasks { tasks {
// root project has no useful artifacts // root project has no useful artifacts
withType<Jar> { withType<Jar> {

View File

@ -1,24 +0,0 @@
object Versions {
// Common compiled
const val adventure = "4.7.0"
const val gson = "2.8.6"
const val fastUtil = "8.3.1"
const val openNBT = "2.0-SNAPSHOT"
const val javassist = "3.27.0-GA"
// Common provided
const val netty = "4.0.20.Final"
const val guava = "17.0"
const val snakeYaml = "1.18"
const val jUnit = "5.6.3"
const val checkerQual = "3.12.0"
// Platforms
const val paper = "1.16.5-R0.1-SNAPSHOT"
const val legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
const val bungee = "1.16-R0.5-SNAPSHOT"
const val sponge = "5.0.0"
const val legacySponge = "4.0.0"
const val velocity = "1.1.0-SNAPSHOT"
}

View File

@ -1,8 +1,11 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.gradle.api.JavaVersion
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.jvm.tasks.Jar import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.invoke import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType import org.gradle.kotlin.dsl.withType
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
@ -88,3 +91,10 @@ fun Project.latestCommitHash(): String {
} }
return byteOut.toString(Charsets.UTF_8.name()).trim() return byteOut.toString(Charsets.UTF_8.name()).trim()
} }
fun Project.configureJavaTarget(version: Int) {
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.toVersion(version)
targetCompatibility = JavaVersion.toVersion(version)
}
}

View File

@ -1,6 +1,6 @@
dependencies { dependencies {
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
compileOnly("org.bukkit", "bukkit", Versions.legacyBukkit) { compileOnly(libs.legacyBukkit) {
exclude("junit", "junit") exclude("junit", "junit")
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")
exclude("javax.persistence", "persistence-api") exclude("javax.persistence", "persistence-api")

View File

@ -1,8 +1,8 @@
dependencies { dependencies {
implementation(project(":viaversion-bukkit-legacy")) implementation(projects.viaversionBukkitLegacy)
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
implementation("org.javassist", "javassist", Versions.javassist) implementation(libs.javassist)
compileOnly("com.destroystokyo.paper", "paper-api", Versions.paper) { compileOnly(libs.paper) {
exclude("junit", "junit") exclude("junit", "junit")
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")
exclude("javax.persistence", "persistence-api") exclude("javax.persistence", "persistence-api")

View File

@ -1,7 +1,7 @@
dependencies { dependencies {
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
implementation(project(":java-compat")) implementation(projects.javaCompat)
compileOnly("net.md-5", "bungeecord-api", Versions.bungee) compileOnly(libs.bungee)
} }
configure<JavaPluginConvention> { configure<JavaPluginConvention> {

View File

@ -1,5 +1,5 @@
plugins { plugins {
id("net.kyori.blossom") version "1.2.0" id("net.kyori.blossom")
} }
blossom { blossom {
@ -8,5 +8,5 @@ blossom {
} }
dependencies { dependencies {
api(project(":viaversion-api")) api(projects.viaversionApi)
} }

View File

@ -1,3 +1,3 @@
dependencies { dependencies {
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
} }

58
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,58 @@
metadata.format.version = "1.0"
[versions]
adventure = "4.7.0"
gson = "2.8.6"
fastutil = "8.3.1"
openNBT = "2.0-SNAPSHOT"
javassist = "3.27.0-GA"
# Common provided
netty = "4.0.20.Final"
guava = "17.0"
snakeYaml = "1.18"
junit = "5.6.3"
checkerQual = "3.12.0"
# Platforms
paper = "1.16.5-R0.1-SNAPSHOT"
legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
bungee = "1.16-R0.5-SNAPSHOT"
sponge = "5.0.0"
legacySponge = "4.0.0"
velocity = "1.1.0-SNAPSHOT"
[libraries]
adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-text-serializer-gson = { group = "net.kyori", name = "adventure-text-serializer-gson", version.ref = "adventure" }
adventure-text-serializer-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" }
openNBT = { group = "com.viaversion", name = "opennbt", version.ref = "openNBT" }
javassist = { group = "org.javassist", name = "javassist", version.ref = "javassist" }
netty = { group = "io.netty", name = "netty-all", version.ref = "netty" }
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
snakeYaml = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeYaml" }
jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
checkerQual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerQual" }
paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "paper" }
legacyBukkit = { group = "org.bukkit", name = "bukkit", version.ref = "legacyBukkit" }
bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" }
sponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "sponge" }
legacySponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "legacySponge" }
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
[bundles]
adventure = ["adventure-api", "adventure-text-serializer-gson", "adventure-text-serializer-legacy"]
junit = ["jupiter-api", "jupiter-engine"]

View File

@ -1,8 +1,8 @@
dependencies { dependencies {
api(project(":java-compat:java-compat-common")) api(projects.javaCompat.javaCompatCommon)
api(project(":java-compat:java-compat-8")) api(projects.javaCompat.javaCompat8)
api(project(":java-compat:java-compat-9")) api(projects.javaCompat.javaCompat9)
api(project(":java-compat:java-compat-16")) api(projects.javaCompat.javaCompat16)
} }
configure<JavaPluginConvention> { configure<JavaPluginConvention> {

View File

@ -1,10 +1,7 @@
dependencies { dependencies {
api(project(":java-compat:java-compat-common")) api(projects.javaCompat.javaCompatCommon)
} }
configure<JavaPluginConvention> { // This is for Java 16, but the minimum required for this
// This is for Java 16, but the minimum required for this // is actually just Java 9!
// is actually just Java 9! configureJavaTarget(9)
sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
}

View File

@ -1,3 +1,5 @@
dependencies { dependencies {
api(project(":java-compat:java-compat-common")) api(projects.javaCompat.javaCompatCommon)
} }
configureJavaTarget(8)

View File

@ -1,8 +1,5 @@
dependencies { dependencies {
api(project(":java-compat:java-compat-common")) api(projects.javaCompat.javaCompatCommon)
} }
configure<JavaPluginConvention> { configureJavaTarget(9)
sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
}

View File

@ -1,5 +1,8 @@
rootProject.name = "viaversion-parent" rootProject.name = "viaversion-parent"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("VERSION_CATALOGS")
include("adventure") include("adventure")
include("java-compat", "java-compat:java-compat-common", "java-compat:java-compat-8", include("java-compat", "java-compat:java-compat-common", "java-compat:java-compat-8",
"java-compat:java-compat-9", "java-compat:java-compat-16") "java-compat:java-compat-9", "java-compat:java-compat-16")

View File

@ -1,4 +1,4 @@
dependencies { dependencies {
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
compileOnly("org.spongepowered", "spongeapi", Versions.legacySponge) compileOnly(libs.legacySponge)
} }

View File

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation(project(":viaversion-sponge-legacy")) implementation(projects.viaversionSpongeLegacy)
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
compileOnly("org.spongepowered","spongeapi", Versions.sponge) compileOnly(libs.sponge)
} }

View File

@ -1,22 +1,26 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("com.github.johnrengelman.shadow")
}
tasks { tasks {
withType<ShadowJar> { withType<ShadowJar> {
archiveClassifier.set("") archiveClassifier.set("")
archiveFileName.set("ViaVersion-${project.version}.jar") archiveFileName.set("ViaVersion-${project.version}.jar")
destinationDirectory.set(rootProject.projectDir.resolve("build/libs")) destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE duplicatesStrategy = DuplicatesStrategy.EXCLUDE
arrayOf( sequenceOf(
"bukkit", rootProject.projects.viaversionBukkit,
"bungee", rootProject.projects.viaversionBungee,
"fabric", rootProject.projects.viaversionFabric,
"sponge", rootProject.projects.viaversionSponge,
"velocity" rootProject.projects.viaversionVelocity,
).forEach { ).map { it.dependencyProject }.forEach { subproject ->
val subProject = rootProject.project(":viaversion-$it") val shadowJarTask = subproject.tasks.getByName("shadowJar", ShadowJar::class)
val shadowJarTask = subProject.tasks.getByName("shadowJar")
from(zipTree(shadowJarTask.outputs.files.singleFile))
dependsOn(shadowJarTask) dependsOn(shadowJarTask)
dependsOn(subproject.tasks.withType<Jar>())
from(zipTree(shadowJarTask.archiveFile))
} }
} }
build { build {

View File

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation(project(":viaversion-common")) implementation(projects.viaversionCommon)
compileOnly("com.velocitypowered", "velocity-api", Versions.velocity) compileOnly(libs.velocity)
annotationProcessor("com.velocitypowered", "velocity-api", Versions.velocity) annotationProcessor(libs.velocity)
} }