Build script improvements

This commit is contained in:
jmp 2021-05-24 21:58:34 -07:00 committed by Nassim
parent 2d2a5fa79c
commit e2d9e44be3
16 changed files with 234 additions and 202 deletions

View File

@ -7,11 +7,14 @@ on: [push, pull_request]
jobs:
build:
# Only run on PRs if the source branch is on a different repo. We do not need run everything twice.
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 11
uses: actions/setup-java@v2
with:

View File

@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("com.github.johnrengelman.shadow")
}
@ -7,11 +5,11 @@ plugins {
// 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
tasks {
withType<ShadowJar> {
shadowJar {
relocate("net.kyori", "com.viaversion.viaversion.libs.kyori")
}
getByName("build") {
dependsOn(withType<ShadowJar>())
build {
dependsOn(shadowJar)
}
}
@ -23,3 +21,5 @@ dependencies {
exclude("com.google.code.gson", "gson")
}
}
publishShadowJar()

View File

@ -1,5 +1,6 @@
plugins {
id("net.kyori.blossom")
id("via.shadow-conventions")
}
blossom {

View File

@ -7,5 +7,6 @@ repositories {
}
dependencies {
// version must be manually kept in sync with the one in root project settings.gradle.kts
implementation("gradle.plugin.com.github.jengelman.gradle.plugins", "shadow", "7.0.0")
}

View File

@ -0,0 +1,44 @@
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import java.io.ByteArrayOutputStream
fun Project.publishShadowJar() {
configurePublication {
artifact(tasks["shadowJar"])
artifact(tasks["sourcesJar"])
}
}
fun Project.publishJavaComponents() {
configurePublication {
from(components["java"])
}
}
private fun Project.configurePublication(configurer: MavenPublication.() -> Unit) {
extensions.configure<PublishingExtension> {
publications.named<MavenPublication>("mavenJava") {
apply(configurer)
}
}
}
fun Project.latestCommitHash(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun JavaPluginExtension.javaTarget(version: Int) {
sourceCompatibility = JavaVersion.toVersion(version)
targetCompatibility = JavaVersion.toVersion(version)
}

View File

@ -0,0 +1,42 @@
plugins {
`java-library`
`maven-publish`
}
tasks {
// Variable replacements
processResources {
filesMatching(listOf("plugin.yml", "mcmod.info", "fabric.mod.json", "bungee.yml")) {
expand("version" to project.version, "description" to project.description)
}
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
}
}
java {
javaTarget(8)
withSourcesJar()
withJavadocJar() // todo: do we need javadoc enabled for every module?
}
publishing {
publications.create<MavenPublication>("mavenJava") {
groupId = rootProject.group as String
artifactId = project.name
version = rootProject.version as String
}
repositories.maven {
name = "Via"
url = uri("https://repo.viaversion.com/")
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
}
}
}

View File

@ -0,0 +1,10 @@
plugins {
id("via.shadow-conventions")
}
tasks {
shadowJar {
archiveFileName.set("ViaVersion-${project.name.substringAfter("viaversion-").capitalize()}-${project.version}.jar")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
}
}

View File

@ -0,0 +1,55 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.named
plugins {
id("via.base-conventions")
id("com.github.johnrengelman.shadow")
}
tasks {
named<Jar>("jar") {
archiveClassifier.set("unshaded")
from(project.rootProject.file("LICENSE"))
}
val shadowJar = named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
configureRelocations()
configureExcludes()
}
named("build") {
dependsOn(shadowJar)
}
}
publishShadowJar()
fun ShadowJar.configureRelocations() {
relocate("javassist", "com.viaversion.viaversion.libs.javassist")
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
relocate("com.github.steveice10.opennbt", "com.viaversion.viaversion.libs.opennbt")
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
}
fun ShadowJar.configureExcludes() {
// FastUtil - we only want object and int maps
// Object types
exclude("it/unimi/dsi/fastutil/*/*Reference*")
exclude("it/unimi/dsi/fastutil/*/*Boolean*")
exclude("it/unimi/dsi/fastutil/*/*Byte*")
exclude("it/unimi/dsi/fastutil/*/*Short*")
exclude("it/unimi/dsi/fastutil/*/*Float*")
exclude("it/unimi/dsi/fastutil/*/*Double*")
exclude("it/unimi/dsi/fastutil/*/*Long*")
exclude("it/unimi/dsi/fastutil/*/*Char*")
// Map types
exclude("it/unimi/dsi/fastutil/*/*Custom*")
exclude("it/unimi/dsi/fastutil/*/*Tree*")
exclude("it/unimi/dsi/fastutil/*/*Heap*")
exclude("it/unimi/dsi/fastutil/*/*Queue*")
// Crossing fingers
exclude("it/unimi/dsi/fastutil/*/*Big*")
exclude("it/unimi/dsi/fastutil/*/*Synchronized*")
exclude("it/unimi/dsi/fastutil/*/*Unmodifiable*")
exclude("it/unimi/dsi/fastutil/io/*")
}

View File

@ -0,0 +1,5 @@
plugins {
id("via.base-conventions")
}
publishJavaComponents()

View File

@ -1,104 +1,40 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.gradle.api.plugins.JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME
plugins {
`java-library`
`maven-publish`
id("net.kyori.blossom") version "1.2.0" apply false
id("via.build-logic")
}
allprojects {
group = "com.viaversion"
version = "4.0.0-21w20a-SNAPSHOT"
version = property("projectVersion") as String // from gradle.properties
description = "Allow newer clients to join older server versions."
}
subprojects {
apply<JavaLibraryPlugin>()
apply<MavenPublishPlugin>()
tasks {
// Variable replacements
processResources {
filesMatching(listOf("plugin.yml", "mcmod.info", "fabric.mod.json", "bungee.yml")) {
expand("version" to project.version, "description" to project.description)
}
}
withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
}
withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
}
}
repositories {
maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
maven("https://repo.spongepowered.org/repository/maven-public/")
maven("https://libraries.minecraft.net")
mavenCentral()
}
dependencies {
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
testImplementation(rootProject.libs.netty)
testImplementation(rootProject.libs.guava)
testImplementation(rootProject.libs.bundles.junit)
}
configureJavaTarget(8)
java {
withSourcesJar()
withJavadocJar()
}
}
// Configure shadow tasks before the publishing task
sequenceOf(
val platforms = setOf(
projects.viaversionBukkit,
projects.viaversionBungee,
projects.viaversionFabric,
projects.viaversionSponge,
projects.viaversionVelocity
).map { it.dependencyProject }.forEach { project ->
project.configureShadowJar()
}
).map { it.dependencyProject }
projects.viaversionApi.dependencyProject.configureShadowJarAPI()
projects.viaversion.dependencyProject.apply<ShadowPlugin>()
val special = setOf(
projects.viaversion,
projects.viaversionApi,
projects.adventure
).map { it.dependencyProject }
subprojects {
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = rootProject.group as String
artifactId = project.name
version = rootProject.version as String
if (plugins.hasPlugin(ShadowPlugin::class.java)) {
artifact(tasks["shadowJar"])
} else {
from(components["java"])
}
}
}
repositories.maven {
name = "Via"
url = uri("https://repo.viaversion.com/")
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
}
}
}
when (this) {
in platforms -> plugins.apply("via.platform-conventions")
in special -> plugins.apply("via.base-conventions")
else -> plugins.apply("via.standard-conventions")
}
tasks {
// root project has no useful artifacts
withType<Jar> {
onlyIf { false }
dependencies {
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.netty)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.guava)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.bundles.junit)
}
}

View File

@ -1,100 +0,0 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType
import java.io.ByteArrayOutputStream
fun Project.configureShadowJarAPI() {
apply<ShadowPlugin>()
tasks {
withType<ShadowJar> {
archiveClassifier.set("")
configureRelocations()
configureExcludes()
}
getByName("build") {
dependsOn(withType<ShadowJar>())
}
withType<Jar> {
if (name == "jar") {
archiveClassifier.set("unshaded")
}
}
}
}
fun Project.configureShadowJar() {
apply<ShadowPlugin>()
tasks {
withType<ShadowJar> {
archiveClassifier.set("")
archiveFileName.set("ViaVersion-${project.name.substringAfter("viaversion-").capitalize()}-${project.version}.jar")
destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
configureRelocations()
configureExcludes()
}
getByName("build") {
dependsOn(withType<ShadowJar>())
}
withType<Jar> {
if (name == "jar") {
archiveClassifier.set("unshaded")
}
from(project.parent!!.file("LICENSE")) {
into("")
}
}
}
}
private fun ShadowJar.configureRelocations() {
relocate("javassist", "com.viaversion.viaversion.libs.javassist")
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
relocate("com.github.steveice10.opennbt", "com.viaversion.viaversion.libs.opennbt")
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
}
private fun ShadowJar.configureExcludes() {
// FastUtil - we only want object and int maps
// Object types
exclude("it/unimi/dsi/fastutil/*/*Reference*")
exclude("it/unimi/dsi/fastutil/*/*Boolean*")
exclude("it/unimi/dsi/fastutil/*/*Byte*")
exclude("it/unimi/dsi/fastutil/*/*Short*")
exclude("it/unimi/dsi/fastutil/*/*Float*")
exclude("it/unimi/dsi/fastutil/*/*Double*")
exclude("it/unimi/dsi/fastutil/*/*Long*")
exclude("it/unimi/dsi/fastutil/*/*Char*")
// Map types
exclude("it/unimi/dsi/fastutil/*/*Custom*")
exclude("it/unimi/dsi/fastutil/*/*Tree*")
exclude("it/unimi/dsi/fastutil/*/*Heap*")
exclude("it/unimi/dsi/fastutil/*/*Queue*")
// Crossing fingers
exclude("it/unimi/dsi/fastutil/*/*Big*")
exclude("it/unimi/dsi/fastutil/*/*Synchronized*")
exclude("it/unimi/dsi/fastutil/*/*Unmodifiable*")
exclude("it/unimi/dsi/fastutil/io/*")
}
fun Project.latestCommitHash(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
standardOutput = byteOut
}
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,3 +1,7 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=4.0.0-21w20a-SNAPSHOT
# Gradle properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true

View File

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

View File

@ -1,8 +1,33 @@
rootProject.name = "viaversion-parent"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
// configures repositories for all projects
repositories {
maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
maven("https://repo.spongepowered.org/repository/maven-public/")
maven("https://libraries.minecraft.net")
mavenCentral()
}
// only use these repos
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
pluginManagement {
// default plugin versions
plugins {
id("net.kyori.blossom") version "1.2.0"
id("com.github.johnrengelman.shadow") version "7.0.0"
}
}
rootProject.name = "viaversion-parent"
includeBuild("build-logic")
include("adventure")
include("java-compat", "java-compat:java-compat-common", "java-compat:java-compat-unsafe")

View File

@ -1,7 +1,11 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("com.github.johnrengelman.shadow")
}
tasks {
withType<ShadowJar> {
shadowJar {
archiveClassifier.set("")
archiveFileName.set("ViaVersion-${project.version}.jar")
destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
@ -13,13 +17,15 @@ tasks {
rootProject.projects.viaversionSponge,
rootProject.projects.viaversionVelocity,
).map { it.dependencyProject }.forEach { subproject ->
val shadowJarTask = subproject.tasks.getByName("shadowJar", ShadowJar::class)
val shadowJarTask = subproject.tasks.named<ShadowJar>("shadowJar").forUseAtConfigurationTime().get()
dependsOn(shadowJarTask)
dependsOn(subproject.tasks.withType<Jar>())
from(zipTree(shadowJarTask.archiveFile))
}
}
build {
dependsOn(withType<ShadowJar>())
dependsOn(shadowJar)
}
}
publishShadowJar()