3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Build script improvements

Dieser Commit ist enthalten in:
jmp 2021-05-24 21:58:34 -07:00 committet von Nassim
Ursprung 2d2a5fa79c
Commit e2d9e44be3
16 geänderte Dateien mit 234 neuen und 202 gelöschten Zeilen

Datei anzeigen

@ -7,11 +7,14 @@ on: [push, pull_request]
jobs: jobs:
build: 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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v2 uses: actions/setup-java@v2
with: with:

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -7,5 +7,6 @@ repositories {
} }
dependencies { 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") implementation("gradle.plugin.com.github.jengelman.gradle.plugins", "shadow", "7.0.0")
} }

Datei anzeigen

@ -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)
}

Datei anzeigen

@ -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")
}
}
}

Datei anzeigen

@ -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"))
}
}

Datei anzeigen

@ -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/*")
}

Datei anzeigen

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

Datei anzeigen

@ -1,104 +1,40 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import org.gradle.api.plugins.JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME
plugins { plugins {
`java-library` id("via.build-logic")
`maven-publish`
id("net.kyori.blossom") version "1.2.0" apply false
} }
allprojects { allprojects {
group = "com.viaversion" 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." description = "Allow newer clients to join older server versions."
} }
val platforms = setOf(
projects.viaversionBukkit,
projects.viaversionBungee,
projects.viaversionFabric,
projects.viaversionSponge,
projects.viaversionVelocity
).map { it.dependencyProject }
val special = setOf(
projects.viaversion,
projects.viaversionApi,
projects.adventure
).map { it.dependencyProject }
subprojects { subprojects {
apply<JavaLibraryPlugin>() when (this) {
apply<MavenPublishPlugin>() in platforms -> plugins.apply("via.platform-conventions")
in special -> plugins.apply("via.base-conventions")
tasks { else -> plugins.apply("via.standard-conventions")
// 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 { 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(rootProject.libs.netty) TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.netty)
testImplementation(rootProject.libs.guava) TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.guava)
testImplementation(rootProject.libs.bundles.junit) TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.bundles.junit)
}
configureJavaTarget(8)
java {
withSourcesJar()
withJavadocJar()
}
}
// Configure shadow tasks before the publishing task
sequenceOf(
projects.viaversionBukkit,
projects.viaversionBungee,
projects.viaversionFabric,
projects.viaversionSponge,
projects.viaversionVelocity
).map { it.dependencyProject }.forEach { project ->
project.configureShadowJar()
}
projects.viaversionApi.dependencyProject.configureShadowJarAPI()
projects.viaversion.dependencyProject.apply<ShadowPlugin>()
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")
}
}
}
}
tasks {
// root project has no useful artifacts
withType<Jar> {
onlyIf { false }
} }
} }

Datei anzeigen

@ -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)
}
}

Datei anzeigen

@ -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.daemon=true
org.gradle.configureondemand=true org.gradle.configureondemand=true
org.gradle.parallel=true org.gradle.parallel=true

Datei anzeigen

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

Datei anzeigen

@ -1,8 +1,33 @@
rootProject.name = "viaversion-parent"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("VERSION_CATALOGS") 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("adventure")
include("java-compat", "java-compat:java-compat-common", "java-compat:java-compat-unsafe") include("java-compat", "java-compat:java-compat-common", "java-compat:java-compat-unsafe")

Datei anzeigen

@ -1,7 +1,11 @@
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> { 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"))
@ -13,13 +17,15 @@ tasks {
rootProject.projects.viaversionSponge, rootProject.projects.viaversionSponge,
rootProject.projects.viaversionVelocity, rootProject.projects.viaversionVelocity,
).map { it.dependencyProject }.forEach { subproject -> ).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(shadowJarTask)
dependsOn(subproject.tasks.withType<Jar>()) dependsOn(subproject.tasks.withType<Jar>())
from(zipTree(shadowJarTask.archiveFile)) from(zipTree(shadowJarTask.archiveFile))
} }
} }
build { build {
dependsOn(withType<ShadowJar>()) dependsOn(shadowJar)
} }
} }
publishShadowJar()