mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-21 12:07:38 +01:00
Update build scripts
This commit is contained in:
parent
fb368a9ebe
commit
27b4933262
12
build-logic/build.gradle.kts
Normal file
12
build-logic/build.gradle.kts
Normal file
@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
44
build-logic/src/main/kotlin/extensions.kt
Normal file
44
build-logic/src/main/kotlin/extensions.kt
Normal 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)
|
||||
}
|
42
build-logic/src/main/kotlin/vb.base-conventions.gradle.kts
Normal file
42
build-logic/src/main/kotlin/vb.base-conventions.gradle.kts
Normal 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, "url" to "https://github.com/ViaVersion/ViaBackwards")
|
||||
}
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
|
||||
}
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
javaTarget(8)
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
id("vb.shadow-conventions")
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveFileName.set("ViaBackwards-${project.name.substringAfter("viabackwards-").capitalize()}-${project.version}.jar")
|
||||
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
|
||||
}
|
||||
}
|
29
build-logic/src/main/kotlin/vb.shadow-conventions.gradle.kts
Normal file
29
build-logic/src/main/kotlin/vb.shadow-conventions.gradle.kts
Normal file
@ -0,0 +1,29 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.named
|
||||
|
||||
plugins {
|
||||
id("vb.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()
|
||||
}
|
||||
named("build") {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
publishShadowJar()
|
||||
|
||||
fun ShadowJar.configureRelocations() {
|
||||
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
|
||||
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
plugins {
|
||||
id("vb.base-conventions")
|
||||
}
|
||||
|
||||
publishJavaComponents()
|
@ -1,9 +1,6 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("net.kyori.blossom") version "1.2.0" apply false
|
||||
base
|
||||
id("vb.build-logic")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -12,87 +9,23 @@ allprojects {
|
||||
description = "Allow older clients to join newer 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,
|
||||
"url" to "https://github.com/ViaVersion/ViaBackwards")
|
||||
}
|
||||
}
|
||||
withType<Javadoc> {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
|
||||
}
|
||||
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/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
|
||||
// Configure shadow tasks before the publishing task
|
||||
sequenceOf(
|
||||
val platforms = setOf(
|
||||
projects.viabackwardsBukkit,
|
||||
projects.viabackwardsBungee,
|
||||
projects.viabackwardsFabric,
|
||||
projects.viabackwardsSponge,
|
||||
projects.viabackwardsVelocity
|
||||
).map { it.dependencyProject }.forEach { project ->
|
||||
project.configureShadowJar()
|
||||
}
|
||||
).map { it.dependencyProject }
|
||||
|
||||
projects.viabackwards.dependencyProject.apply<ShadowPlugin>()
|
||||
// Would otherwise contain api/depdency modules if at some point needed
|
||||
val special = setOf(
|
||||
projects.viabackwards
|
||||
).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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<Jar> {
|
||||
onlyIf { false }
|
||||
when (this) {
|
||||
in platforms -> plugins.apply("vb.platform-conventions")
|
||||
in special -> plugins.apply("vb.base-conventions")
|
||||
else -> plugins.apply("vb.standard-conventions")
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.jengelman.gradle.plugins", "shadow", "6.1.0")
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.invoke
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
fun Project.configureShadowJar() {
|
||||
apply<ShadowPlugin>()
|
||||
tasks {
|
||||
withType<ShadowJar> {
|
||||
archiveClassifier.set("")
|
||||
archiveFileName.set("ViaBackwards-${project.name.substringAfter("viabackwards-").capitalize()}-${project.version}.jar")
|
||||
destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
|
||||
configureRelocations()
|
||||
}
|
||||
getByName("build") {
|
||||
dependsOn(withType<ShadowJar>())
|
||||
}
|
||||
withType<Jar> {
|
||||
if (name == "jar") {
|
||||
archiveClassifier.set("unshaded")
|
||||
}
|
||||
from(project.parent!!.file("LICENSE")) {
|
||||
into("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ShadowJar.configureRelocations() {
|
||||
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
|
||||
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
@ -12,4 +12,8 @@ dependencies {
|
||||
compileOnlyApi(libs.netty)
|
||||
compileOnlyApi(libs.guava)
|
||||
compileOnlyApi(libs.checkerQual)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
@ -1,8 +1,29 @@
|
||||
rootProject.name = "viabackwards-parent"
|
||||
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
|
||||
rootProject.name = "viabackwards-parent"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
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/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
||||
pluginManagement {
|
||||
plugins {
|
||||
id("net.kyori.blossom") version "1.2.0"
|
||||
id("com.github.johnrengelman.shadow") version "7.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
includeBuild("build-logic")
|
||||
|
||||
setupViaSubproject("common")
|
||||
setupViaSubproject("bukkit")
|
||||
setupViaSubproject("bungee")
|
||||
|
@ -1,25 +1,41 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
val platforms = setOf(
|
||||
projects.viabackwardsBukkit,
|
||||
projects.viabackwardsBungee,
|
||||
projects.viabackwardsFabric,
|
||||
projects.viabackwardsSponge,
|
||||
projects.viabackwardsVelocity
|
||||
).map { it.dependencyProject }
|
||||
|
||||
tasks {
|
||||
withType<ShadowJar> {
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
archiveFileName.set("ViaBackwards-${project.version}.jar")
|
||||
destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
sequenceOf(
|
||||
rootProject.projects.viabackwardsBukkit,
|
||||
rootProject.projects.viabackwardsBungee,
|
||||
rootProject.projects.viabackwardsFabric,
|
||||
rootProject.projects.viabackwardsSponge,
|
||||
rootProject.projects.viabackwardsVelocity,
|
||||
).map { it.dependencyProject }.forEach { subproject ->
|
||||
val shadowJarTask = subproject.tasks.getByName("shadowJar", ShadowJar::class)
|
||||
platforms.forEach { platform ->
|
||||
val shadowJarTask = platform.tasks.getByName("shadowJar", ShadowJar::class)
|
||||
dependsOn(shadowJarTask)
|
||||
dependsOn(subproject.tasks.withType<Jar>())
|
||||
dependsOn(platform.tasks.withType<Jar>())
|
||||
from(zipTree(shadowJarTask.archiveFile))
|
||||
}
|
||||
}
|
||||
build {
|
||||
dependsOn(withType<ShadowJar>())
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
sourcesJar {
|
||||
rootProject.subprojects.forEach { subproject ->
|
||||
if (subproject == project) return@forEach
|
||||
val platformSourcesJarTask = subproject.tasks.findByName("sourcesJar") as? Jar ?: return@forEach
|
||||
dependsOn(platformSourcesJarTask)
|
||||
from(zipTree(platformSourcesJarTask.archiveFile))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishShadowJar()
|
||||
|
Loading…
Reference in New Issue
Block a user