Skip to content

Commit c16c16a

Browse files
committed
Rework gradle-build setup
1 parent 4f8e814 commit c16c16a

14 files changed

+345
-258
lines changed

Diff for: .gitattributes

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Normalize as LF in the repository, OS native locally
2+
* text=auto
3+
4+
*.bat text eol=crlf
5+
gradlew text eol=lf
6+
*.sh text eol=lf
7+
*.conf text eol=lf
8+
9+
*.java text
10+
*.java diff=java
11+
12+
# Binary files that should not be modified
13+
*.dat binary
14+
*.db binary
15+
*.icns binary
16+
*.ico binary
17+
*.jar binary
18+
*.jks binary
19+
*.jpg binary
20+
*.key binary
21+
*.png binary
22+
*.ttf binary
23+
*.wav binary
24+
JavaApplicationStub binary

Diff for: build.gradle.kts

+6-127
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,13 @@
1-
import java.io.IOException
2-
import java.util.concurrent.TimeoutException
3-
41
plugins {
5-
java
6-
`java-library`
7-
`maven-publish`
8-
id("com.diffplug.spotless") version "6.1.2"
9-
}
10-
11-
fun String.runCommand(): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
12-
.directory(projectDir)
13-
.redirectOutput(ProcessBuilder.Redirect.PIPE)
14-
.redirectError(ProcessBuilder.Redirect.PIPE)
15-
.start()
16-
.apply {
17-
if (!waitFor(10, TimeUnit.SECONDS)) {
18-
throw TimeoutException("Failed to execute command: '" + this@runCommand + "'")
19-
}
20-
}
21-
.run {
22-
val error = errorStream.bufferedReader().readText().trim()
23-
if (error.isNotEmpty()) {
24-
throw IOException(error)
25-
}
26-
inputStream.bufferedReader().readText().trim()
27-
}
28-
29-
val gitHash = "git rev-parse --verify HEAD".runCommand()
30-
val clean = "git status --porcelain".runCommand().isEmpty()
31-
val lastTag = "git describe --tags --abbrev=0".runCommand()
32-
val lastVersion = lastTag.substring(1) // remove the leading 'v'
33-
val commits = "git rev-list --count $lastTag..HEAD".runCommand()
34-
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
35-
36-
group = "de.bluecolored.bluemap"
37-
version = lastVersion +
38-
(if (commits == "0") "" else "-$commits") +
39-
(if (clean) "" else "-dirty")
40-
41-
println("Version: $version")
42-
43-
val javaTarget = 16
44-
java {
45-
sourceCompatibility = JavaVersion.toVersion(javaTarget)
46-
targetCompatibility = JavaVersion.toVersion(javaTarget)
47-
48-
withSourcesJar()
49-
withJavadocJar()
50-
}
51-
52-
repositories {
53-
mavenCentral()
2+
bluemap.base
543
}
554

565
dependencies {
57-
api ("com.flowpowered:flow-math:1.0.3")
58-
api ("com.google.code.gson:gson:2.8.0")
59-
60-
compileOnly ("org.jetbrains:annotations:23.0.0")
61-
}
62-
63-
spotless {
64-
java {
65-
target ("src/*/java/**/*.java")
66-
67-
licenseHeaderFile("LICENSE_HEADER")
68-
indentWithSpaces()
69-
trimTrailingWhitespace()
70-
}
71-
}
72-
73-
tasks.withType(JavaCompile::class).configureEach {
74-
options.apply {
75-
encoding = "utf-8"
76-
}
77-
}
78-
79-
tasks.withType(AbstractArchiveTask::class).configureEach {
80-
isReproducibleFileOrder = true
81-
isPreserveFileTimestamps = false
82-
}
83-
84-
tasks.javadoc {
85-
options {
86-
(this as? StandardJavadocDocletOptions)?.apply {
87-
links(
88-
"https://docs.oracle.com/en/java/javase/16/docs/api/",
89-
"https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/",
90-
"https://javadoc.io/doc/com.google.code.gson/gson/2.8.0/",
91-
)
92-
addStringOption("Xdoclint:none", "-quiet")
93-
addBooleanOption("html5", true)
94-
}
95-
}
96-
}
97-
98-
tasks.processResources {
99-
from("src/main/resources") {
100-
include("de/bluecolored/bluemap/api/version.json")
101-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
102-
103-
expand (
104-
"version" to project.version,
105-
"gitHash" to gitHash + if (clean) "" else " (dirty)"
106-
)
107-
}
108-
}
109-
110-
publishing {
111-
repositories {
112-
maven {
113-
name = "bluecolored"
114-
115-
val releasesRepoUrl = "https://repo.bluecolored.de/releases"
116-
val snapshotsRepoUrl = "https://repo.bluecolored.de/snapshots"
117-
url = uri(if (version == lastVersion) releasesRepoUrl else snapshotsRepoUrl)
6+
api ( libs.flow.math )
7+
api ( libs.gson )
1188

119-
credentials {
120-
username = project.findProperty("bluecoloredUsername") as String? ?: System.getenv("BLUECOLORED_USERNAME")
121-
password = project.findProperty("bluecoloredPassword") as String? ?: System.getenv("BLUECOLORED_PASSWORD")
122-
}
123-
}
124-
}
125-
publications {
126-
create<MavenPublication>("maven") {
127-
groupId = project.group.toString()
128-
artifactId = project.name
129-
version = project.version.toString()
9+
compileOnly ( libs.jetbrains.annotations )
10+
compileOnly ( libs.lombok )
13011

131-
from(components["java"])
132-
}
133-
}
12+
annotationProcessor ( libs.lombok )
13413
}

Diff for: buildSrc/build.gradle.kts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
dependencies {
11+
fun plugin(dependency: Provider<PluginDependency>) = dependency.map {
12+
"${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}"
13+
}
14+
15+
implementation ( plugin( libs.plugins.spotless ) )
16+
implementation ( plugin( libs.plugins.shadow ) )
17+
}

Diff for: buildSrc/settings.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// use version-catalog from root project
3+
dependencyResolutionManagement {
4+
versionCatalogs {
5+
register("libs") {
6+
from(files("../gradle/libs.versions.toml"))
7+
}
8+
}
9+
}

Diff for: buildSrc/src/main/kotlin/bluemap.base.gradle.kts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
java
3+
`java-library`
4+
id ( "com.diffplug.spotless" )
5+
}
6+
7+
group = "de.bluecolored.bluemap"
8+
version = gitVersion()
9+
10+
repositories {
11+
maven ("https://repo.bluecolored.de/releases") {
12+
content { includeGroupByRegex ("de\\.bluecolored\\..*") }
13+
}
14+
maven ("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
15+
content { includeGroup ("org.spigotmc") }
16+
}
17+
18+
mavenCentral()
19+
maven ("https://libraries.minecraft.net")
20+
maven ( "https://maven.minecraftforge.net" )
21+
maven ("https://repo.papermc.io/repository/maven-public/")
22+
}
23+
24+
tasks.withType(JavaCompile::class).configureEach {
25+
options.encoding = "utf-8"
26+
}
27+
28+
tasks.withType(AbstractArchiveTask::class).configureEach {
29+
isReproducibleFileOrder = true
30+
isPreserveFileTimestamps = false
31+
}
32+
33+
java {
34+
toolchain.languageVersion.set(JavaLanguageVersion.of(16))
35+
withSourcesJar()
36+
withJavadocJar()
37+
}
38+
39+
tasks.javadoc {
40+
(options as StandardJavadocDocletOptions).apply {
41+
links(
42+
"https://docs.oracle.com/en/java/javase/16/docs/api/",
43+
"https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/",
44+
"https://javadoc.io/doc/com.google.code.gson/gson/2.8.9/",
45+
)
46+
addStringOption("Xdoclint:none", "-quiet")
47+
addBooleanOption("html5", true)
48+
}
49+
}
50+
51+
tasks.test {
52+
useJUnitPlatform()
53+
}
54+
55+
spotless {
56+
java {
57+
target ("src/*/java/**/*.java")
58+
59+
licenseHeaderFile(rootProject.file("LICENSE_HEADER"))
60+
indentWithSpaces()
61+
trimTrailingWhitespace()
62+
}
63+
}

Diff for: buildSrc/src/main/kotlin/versioning.kt

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import org.gradle.api.Project
2+
import java.io.IOException
3+
import java.util.concurrent.TimeUnit
4+
import java.util.concurrent.TimeoutException
5+
6+
fun Project.gitHash(): String {
7+
return runCommand("git rev-parse --verify HEAD", "-")
8+
}
9+
10+
fun Project.gitClean(): Boolean {
11+
return runCommand("git status --porcelain", "NOT_CLEAN").isEmpty()
12+
}
13+
14+
fun Project.gitVersion(): String {
15+
val lastTag = if (runCommand("git tag", "").isEmpty()) "" else runCommand("git describe --tags --abbrev=0", "")
16+
val lastVersion = if (lastTag.isEmpty()) "0.0" else lastTag.substring(1) // remove the leading 'v'
17+
val commits = runCommand("git rev-list --count $lastTag..HEAD", "0")
18+
val gitVersion = lastVersion +
19+
(if (commits == "0") "" else "-$commits") +
20+
(if (gitClean()) "" else "-dirty")
21+
22+
logger.lifecycle("${project.name} version: $gitVersion")
23+
24+
return gitVersion
25+
}
26+
27+
private fun Project.runCommand(cmd: String, fallback: String? = null): String {
28+
ProcessBuilder(cmd.split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
29+
.directory(projectDir)
30+
.redirectOutput(ProcessBuilder.Redirect.PIPE)
31+
.redirectError(ProcessBuilder.Redirect.PIPE)
32+
.start()
33+
.apply {
34+
if (!waitFor(10, TimeUnit.SECONDS))
35+
throw TimeoutException("Failed to execute command: '$cmd'")
36+
}
37+
.run {
38+
val error = errorStream.bufferedReader().readText().trim()
39+
if (error.isEmpty()) inputStream.bufferedReader().readText().trim()
40+
if (fallback != null) return fallback
41+
throw IOException(error)
42+
}
43+
}

Diff for: gradle.properties

-2
This file was deleted.

Diff for: gradle/libs.versions.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[versions]
2+
junit = "5.8.2"
3+
4+
[libraries]
5+
flow-math = { module = "com.flowpowered:flow-math", version = "1.0.3" }
6+
gson = { module = "com.google.code.gson:gson", version = "2.8.9" }
7+
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "23.0.0" }
8+
junit-core = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
9+
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
10+
lombok = { module = "org.projectlombok:lombok", version = "1.18.32" }
11+
12+
[plugins]
13+
shadow = { id = "io.github.goooler.shadow", version = "8.+" }
14+
spotless = { id = "com.diffplug.spotless", version = "6.+" }

Diff for: gradle/wrapper/gradle-wrapper.jar

5.02 KB
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)