Migrate buildSrc plugins to build-logic

This commit is contained in:
Alexander Städing
2023-03-27 00:00:24 +02:00
committed by Andrew Steinborn
parent 7e932eaad4
commit 3d20c3dd2d
18 changed files with 145 additions and 263 deletions

View File

@@ -0,0 +1,19 @@
@Suppress("DSL_SCOPE_VIOLATION") // fixed in Gradle 8.1
plugins {
`kotlin-dsl`
alias(libs.plugins.spotless)
}
dependencies {
// this is OK as long as the same version catalog is used in the main build and build-logic
// see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation("com.diffplug.spotless:spotless-plugin-gradle:${libs.plugins.spotless.get().version}")
}
spotless {
kotlin {
licenseHeaderFile(rootProject.file("../HEADER.txt"))
}
}

View File

@@ -0,0 +1,15 @@
@file:Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
register("libs") {
from(files("../gradle/libs.versions.toml")) // include from parent project
}
}
}
rootProject.name = "build-logic"

View File

@@ -0,0 +1,6 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
val Project.libs: LibrariesForLibs
get() = rootProject.extensions.getByType()

View File

@@ -0,0 +1,10 @@
plugins {
checkstyle
}
extensions.configure<CheckstyleExtension> {
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
maxErrors = 0
maxWarnings = 0
toolVersion = libs.checkstyle.get().version.toString()
}

View File

@@ -0,0 +1,29 @@
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.withType
import java.io.ByteArrayOutputStream
val currentShortRevision = ByteArrayOutputStream().use {
exec {
executable = "git"
args = listOf("rev-parse", "HEAD")
standardOutput = it
}
it.toString().trim().substring(0, 8)
}
tasks.withType<Jar> {
manifest {
val buildNumber = System.getenv("BUILD_NUMBER")
val velocityHumanVersion: String =
if (project.version.toString().endsWith("-SNAPSHOT")) {
if (buildNumber == null) {
"${project.version} (git-$currentShortRevision)"
} else {
"${project.version} (git-$currentShortRevision-b$buildNumber)"
}
} else {
archiveVersion.get()
}
attributes["Implementation-Version"] = velocityHumanVersion
}
}

View File

@@ -0,0 +1,33 @@
plugins {
java
`maven-publish`
}
extensions.configure<PublishingExtension> {
repositories {
maven {
credentials(PasswordCredentials::class.java)
name = "paper"
val base = "https://papermc.io/repo/repository/maven"
val releasesRepoUrl = "$base-releases/"
val snapshotsRepoUrl = "$base-snapshots/"
setUrl(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
}
}
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name.set("Velocity")
description.set("The modern, next-generation Minecraft server proxy")
url.set("https://www.velocitypowered.com")
scm {
url.set("https://github.com/PaperMC/Velocity")
connection.set("scm:git:https://github.com/PaperMC/Velocity.git")
developerConnection.set("scm:git:https://github.com/PaperMC/Velocity.git")
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
apply<SpotlessPlugin>()
extensions.configure<SpotlessExtension> {
java {
if (project.name == "velocity-api") {
licenseHeaderFile(file("HEADER.txt"))
} else {
licenseHeaderFile(rootProject.file("HEADER.txt"))
}
removeUnusedImports()
}
}