Skip to content

Commit 74424b4

Browse files
authored
Improve gradle (#234)
1 parent 1de2601 commit 74424b4

9 files changed

Lines changed: 245 additions & 179 deletions

File tree

api/build.gradle

Lines changed: 0 additions & 89 deletions
This file was deleted.

api/build.gradle.kts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
@file:Suppress("GroovyAssignabilityCheck")
2+
3+
import net.minecraftforge.licenser.LicenseExtension
4+
import net.minecraftforge.licenser.LicenseProperties
5+
import org.gradle.kotlin.dsl.closureOf
6+
7+
plugins {
8+
`java-library`
9+
`maven-publish`
10+
}
11+
12+
tasks.withType<JavaCompile> {
13+
options.release.set(21)
14+
options.encoding = "UTF-8"
15+
}
16+
17+
dependencies {
18+
compileOnly(libs.minecraft.velocity.api)
19+
api(libs.elytrium.commons.config)
20+
api(libs.elytrium.commons.utils)
21+
api(libs.elytrium.commons.velocity)
22+
api(libs.elytrium.commons.kyori)
23+
api(libs.minecraft.adventure.nbt)
24+
25+
compileOnly(libs.tool.spotbugs.annotations)
26+
}
27+
28+
extensions.configure<LicenseExtension> {
29+
matching(
30+
"**/mcprotocollib/**",
31+
closureOf<LicenseProperties> {
32+
setHeader(rootProject.file("HEADER_MCPROTOCOLLIB.txt"))
33+
}
34+
)
35+
setHeader(file("HEADER.txt"))
36+
}
37+
38+
tasks.named<Javadoc>("javadoc") {
39+
options.encoding = "UTF-8"
40+
(options as? StandardJavadocDocletOptions)?.apply {
41+
source = "21"
42+
links("https://docs.oracle.com/en/java/javase/11/docs/api/")
43+
addStringOption("Xdoclint:none", "-quiet")
44+
if (JavaVersion.current() >= JavaVersion.VERSION_1_9 && JavaVersion.current() < JavaVersion.VERSION_12) {
45+
addBooleanOption("-no-module-directories", true)
46+
}
47+
}
48+
}
49+
50+
val sourcesJar by tasks.registering(Jar::class) {
51+
archiveClassifier.set("sources")
52+
from(sourceSets.main.get().allSource)
53+
}
54+
55+
val javadocJar by tasks.registering(Jar::class) {
56+
archiveClassifier.set("javadoc")
57+
from(tasks.javadoc)
58+
}
59+
60+
publishing {
61+
repositories {
62+
maven {
63+
credentials {
64+
username = System.getenv("ELYTRIUM_MAVEN_USERNAME")
65+
password = System.getenv("ELYTRIUM_MAVEN_PASSWORD")
66+
}
67+
name = "elytrium-repo"
68+
url = uri("https://maven.elytrium.net/repo/")
69+
}
70+
}
71+
72+
publications.create<MavenPublication>("publication") {
73+
from(components["java"])
74+
75+
artifact(javadocJar)
76+
artifact(sourcesJar)
77+
}
78+
}
79+
80+
artifacts {
81+
archives(javadocJar)
82+
archives(sourcesJar)
83+
}
84+
85+
@Suppress("UNCHECKED_CAST")
86+
val getCurrentShortRevision = rootProject.extra["getCurrentShortRevision"] as () -> String
87+
88+
89+
val versionStringProvider = provider {
90+
if (version.toString().contains("-")) {
91+
"${version} (git-${getCurrentShortRevision()})"
92+
} else {
93+
version.toString()
94+
}
95+
}
96+
97+
val copyTask by tasks.register<Copy>("generateTemplates") {
98+
val versionString = versionStringProvider.get()
99+
inputs.property("version", versionString)
100+
from(file("src/main/templates"))
101+
into(layout.buildDirectory.dir("generated/sources/templates"))
102+
expand("version" to versionString)
103+
}
104+
105+
sourceSets.main.configure {
106+
java.srcDir(copyTask.outputs)
107+
}

build.gradle

Lines changed: 0 additions & 62 deletions
This file was deleted.

build.gradle.kts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import com.github.spotbugs.snom.SpotBugsExtension
2+
import com.github.spotbugs.snom.SpotBugsTask
3+
4+
plugins {
5+
java
6+
checkstyle
7+
alias(libs.plugins.gradle.spotbugs) apply false
8+
alias(libs.plugins.gradle.licenser) apply false
9+
}
10+
11+
allprojects {
12+
apply(plugin = "checkstyle")
13+
apply(plugin = "com.github.spotbugs")
14+
apply(plugin = "net.minecraftforge.licenser")
15+
16+
group = "net.elytrium.limboapi"
17+
version = "1.1.27-SNAPSHOT"
18+
19+
tasks.withType<JavaCompile> {
20+
sourceCompatibility = JavaVersion.VERSION_21.toString()
21+
targetCompatibility = JavaVersion.VERSION_21.toString()
22+
}
23+
24+
checkstyle {
25+
toolVersion = "10.12.1"
26+
configFile = file("$rootDir/config/checkstyle/checkstyle.xml")
27+
configProperties = mapOf("configDirectory" to "$rootDir/config/checkstyle")
28+
maxErrors = 0
29+
maxWarnings = 0
30+
}
31+
32+
extensions.configure<SpotBugsExtension> {
33+
excludeFilter.set(file("${rootDir}/config/spotbugs/suppressions.xml"))
34+
}
35+
36+
tasks.withType<SpotBugsTask>() {
37+
reports.create("html") {
38+
required.set(true)
39+
outputLocation.set(layout.buildDirectory.file("reports/spotbugs/main/spotbugs.html"))
40+
setStylesheet("fancy-hist.xsl")
41+
}
42+
}
43+
}
44+
45+
fun getCurrentShortRevision(): String {
46+
val isWindows = System.getProperty("os.name")
47+
.lowercase()
48+
.contains("win")
49+
50+
val process = if (isWindows) {
51+
ProcessBuilder("cmd", "/c", "git rev-parse --short HEAD")
52+
} else {
53+
ProcessBuilder("bash", "-c", "git rev-parse --short HEAD")
54+
}
55+
return process
56+
.start()
57+
.inputStream
58+
.bufferedReader()
59+
.readText()
60+
.trim()
61+
}
62+
63+
// Make the function available to subprojects via extra properties
64+
extra["getCurrentShortRevision"] = ::getCurrentShortRevision

gradle.properties

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
org.gradle.jvmargs=-Xmx4096m
2-
fastPrepareVersion=1.0.13
3-
velocityVersion=3.5.0-SNAPSHOT
4-
nettyVersion=4.1.86.Final
5-
fastutilVersion=8.5.11
6-
bstatsVersion=3.0.0
7-
spotbugsVersion=4.7.3
8-
elytriumCommonsVersion=1.2.3
9-
adventureVersion=4.15.0
102
manifestUrl=https://launchermeta.mojang.com/mc/game/version_manifest.json
113
cacheValidMillis=6000000

gradle/libs.versions.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[versions]
2+
elytrium-commons = "1.2.3" # https://github.com/Elytrium/elytrium-java-commons
3+
elytrium-fastprepare = "1.0.13" #https://github.com/Elytrium/FastPrepareAPI
4+
gradle-licenser = "1.2.0" # https://github.com/CadixDev/licenser
5+
gradle-shadow = "9.4.0" # https://github.com/GradleUp/shadow
6+
gradle-spotbugs = "6.4.8" # https://github.com/spotbugs/spotbugs-gradle-plugin
7+
minecraft-adventure = "4.15.0" # https://github.com/KyoriPowered/adventure
8+
minecraft-bstats = "3.0.0" # https://github.com/Bastian/bStats
9+
minecraft-velocity = "3.5.0-SNAPSHOT" # https://github.com/PaperMC/Velocity
10+
tool-commons-io = "2.6" # https://github.com/apache/commons-io
11+
tool-fastutil = "8.5.11" # https://github.com/vigna/fastutil/
12+
tool-google-guava = "28.0-jre" # https://github.com/google/guava
13+
tool-netty = "4.1.86.Final" # https://github.com/netty/netty
14+
tool-spotbugs-annotations = "4.7.3" # https://github.com/spotbugs/spotbugs
15+
16+
[libraries]
17+
elytrium-commons-config = { module = "net.elytrium.commons:config", version.ref = "elytrium-commons" }
18+
elytrium-commons-kyori = { module = "net.elytrium.commons:kyori", version.ref = "elytrium-commons" }
19+
elytrium-commons-utils = { module = "net.elytrium.commons:utils", version.ref = "elytrium-commons" }
20+
elytrium-commons-velocity = { module = "net.elytrium.commons:velocity", version.ref = "elytrium-commons" }
21+
elytrium-fastprepare = { module = "net.elytrium:fastprepare", version.ref = "elytrium-fastprepare" }
22+
minecraft-adventure-nbt = { module = "net.kyori:adventure-nbt", version.ref = "minecraft-adventure" }
23+
minecraft-bstats-velocity = { module = "org.bstats:bstats-velocity", version.ref = "minecraft-bstats" }
24+
minecraft-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "minecraft-velocity" }
25+
minecraft-velocity-native = { module = "com.velocitypowered:velocity-native", version.ref = "minecraft-velocity" }
26+
minecraft-velocity-proxy = { module = "com.velocitypowered:velocity-proxy", version.ref = "minecraft-velocity" }
27+
tool-commons-io = { module = "commons-io:commons-io", version.ref = "tool-commons-io" }
28+
tool-fastutil = { module = "it.unimi.dsi:fastutil-core", version.ref = "tool-fastutil" }
29+
tool-google-guava = { module = "com.google.guava:guava", version.ref = "tool-google-guava" }
30+
tool-netty-codec = { module = "io.netty:netty-codec", version.ref = "tool-netty" }
31+
tool-netty-handler = { module = "io.netty:netty-handler", version.ref = "tool-netty" }
32+
tool-spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version.ref = "tool-spotbugs-annotations" }
33+
34+
[plugins]
35+
gradle-licenser = { id = "net.minecraftforge.licenser", version.ref = "gradle-licenser" }
36+
gradle-shadow = { id = "com.gradleup.shadow", version.ref = "gradle-shadow" }
37+
gradle-spotbugs = { id = "com.github.spotbugs", version.ref = "gradle-spotbugs" }

0 commit comments

Comments
 (0)