13
0
geforkt von Mirrors/Velocity

Migrate buildSrc plugins to build-logic

Dieser Commit ist enthalten in:
Alexander Städing 2023-03-27 00:00:24 +02:00 committet von Andrew Steinborn
Ursprung 7e932eaad4
Commit 3d20c3dd2d
18 geänderte Dateien mit 145 neuen und 263 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
plugins {
`java-library`
`maven-publish`
id("velocity-publish")
}
java {

19
build-logic/build.gradle.kts Normale Datei
Datei anzeigen

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

Datei anzeigen

@ -1,3 +1,5 @@
@file:Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
mavenCentral()
@ -9,3 +11,5 @@ dependencyResolutionManagement {
}
}
}
rootProject.name = "build-logic"

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,17 +1,14 @@
import com.velocitypowered.script.VelocityCheckstylePlugin
import com.velocitypowered.script.VelocityPublishPlugin
import com.velocitypowered.script.VelocitySpotlessPlugin
plugins {
`java-library`
id("velocity-checkstyle") apply false
id("velocity-spotless") apply false
}
subprojects {
apply<JavaLibraryPlugin>()
apply<VelocityCheckstylePlugin>()
apply<VelocityPublishPlugin>()
apply<VelocitySpotlessPlugin>()
apply(plugin = "velocity-checkstyle")
apply(plugin = "velocity-spotless")
java {
toolchain {
@ -19,12 +16,6 @@ subprojects {
}
}
repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // adventure
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
testImplementation(rootProject.libs.junit)
}

Datei anzeigen

@ -1,37 +0,0 @@
plugins {
`kotlin-dsl`
checkstyle
alias(libs.plugins.indra.publishing)
alias(libs.plugins.spotless)
}
dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:${libs.plugins.spotless.get().version}")
}
gradlePlugin {
plugins {
register("set-manifest-impl-version") {
id = "set-manifest-impl-version"
implementationClass = "com.velocitypowered.script.SetManifestImplVersionPlugin"
}
register("velocity-checkstyle") {
id = "velocity-checkstyle"
implementationClass = "com.velocitypowered.script.VelocityCheckstylePlugin"
}
register("velocity-spotless") {
id = "velocity-spotless"
implementationClass = "com.velocitypowered.script.VelocitySpotlessPlugin"
}
register("velocity-publish") {
id = "velocity-publish"
implementationClass = "com.velocitypowered.script.VelocityPublishPlugin"
}
}
}
spotless {
kotlin {
licenseHeaderFile(project.rootProject.file("../HEADER.txt"))
}
}

Datei anzeigen

@ -1,54 +0,0 @@
/*
* Copyright (C) 2023 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.script
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.withType
import java.io.ByteArrayOutputStream
class SetManifestImplVersionPlugin : Plugin<Project> {
override fun apply(target: Project) = target.afterEvaluate { configure() }
private fun Project.configure() {
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")
var velocityHumanVersion: String
if (project.version.toString().endsWith("-SNAPSHOT")) {
if (buildNumber != null) {
velocityHumanVersion = "${project.version} (git-$currentShortRevision-b$buildNumber)"
} else {
velocityHumanVersion = "${project.version} (git-$currentShortRevision)"
}
} else {
velocityHumanVersion = archiveVersion.get()
}
attributes["Implementation-Version"] = velocityHumanVersion
}
}
}
}

Datei anzeigen

@ -1,38 +0,0 @@
/*
* Copyright (C) 2023 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.script
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.quality.CheckstyleExtension
import org.gradle.api.plugins.quality.CheckstylePlugin
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
class VelocityCheckstylePlugin : Plugin<Project> {
override fun apply(target: Project) = target.configure()
private fun Project.configure() {
apply<CheckstylePlugin>()
extensions.configure<CheckstyleExtension> {
configFile = project.rootProject.file("config/checkstyle/checkstyle.xml")
maxErrors = 0
maxWarnings = 0
toolVersion = "10.6.0"
}
}
}

Datei anzeigen

@ -1,72 +0,0 @@
/*
* Copyright (C) 2023 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.script
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.PasswordCredentials
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByType
class VelocityPublishPlugin : Plugin<Project> {
override fun apply(target: Project) = target.afterEvaluate {
if (target.name != "velocity-proxy") {
configure()
}
}
private fun Project.configure() {
apply<JavaBasePlugin>()
apply<MavenPublishPlugin>()
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")
}
}
}
}
}
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* Copyright (C) 2023 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.script
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import java.io.File
class VelocitySpotlessPlugin : Plugin<Project> {
override fun apply(target: Project) = target.configure()
private fun Project.configure() {
apply<SpotlessPlugin>()
extensions.configure<SpotlessExtension> {
java {
if (project.name == "velocity-api") {
licenseHeaderFile(project.file("HEADER.txt"))
} else {
licenseHeaderFile(project.rootProject.file("HEADER.txt"))
}
removeUnusedImports()
}
}
}
}

Datei anzeigen

@ -18,6 +18,7 @@ brigadier = "com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT"
bstats = "org.bstats:bstats-base:3.0.1"
caffeine = "com.github.ben-manes.caffeine:caffeine:3.1.5"
checker-qual = "org.checkerframework:checker-qual:3.28.0"
checkstyle = "com.puppycrawl.tools:checkstyle:10.9.3"
completablefutures = "com.spotify:completable-futures:0.3.5"
configurate-hocon = { module = "org.spongepowered:configurate-hocon", version.ref = "configurate" }
configurate-yaml = { module = "org.spongepowered:configurate-yaml", version.ref = "configurate" }

Datei anzeigen

@ -1,6 +1,6 @@
plugins {
`java-library`
`maven-publish`
id("velocity-publish")
}
dependencies {

Datei anzeigen

@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCach
plugins {
application
`set-manifest-impl-version`
id("velocity-init-manifest")
alias(libs.plugins.shadow)
}

Datei anzeigen

@ -1,3 +1,23 @@
@file:Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // adventure
maven("https://repo.papermc.io/repository/maven-public/")
}
}
pluginManagement {
includeBuild("build-logic")
repositories {
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
}
@ -6,8 +26,8 @@ rootProject.name = "velocity"
sequenceOf(
"api",
"proxy",
"native",
"proxy",
).forEach {
val project = ":velocity-$it"
include(project)