Convert Velocity buildscripts to Kotlin DSL (#918)
Spiritually indebted to #518 and @alexstaeding. There's a minor break - we're going up to 3.2.0-SNAPSHOT as the API now compiles against Java 11. But this is more academic in practice.
This commit is contained in:
27
buildSrc/build.gradle.kts
Normal file
27
buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
checkstyle
|
||||
id("net.kyori.indra.publishing") version "2.0.6"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://plugins.gradle.org/m2")
|
||||
}
|
||||
|
||||
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-publish") {
|
||||
id = "velocity-publish"
|
||||
implementationClass = "com.velocitypowered.script.VelocityPublishPlugin"
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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"
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user