Skip to content

Commit f494ca4

Browse files
committed
Migrate Gradle from Groovy to Kotlin DSL
1 parent 502d00d commit f494ca4

File tree

6 files changed

+133
-131
lines changed

6 files changed

+133
-131
lines changed

build.gradle

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

build.gradle.kts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import com.diffplug.spotless.LineEnding
2+
3+
plugins {
4+
`java-library`
5+
`maven-publish`
6+
id("com.diffplug.spotless") version "7.2.1"
7+
}
8+
9+
group = "com.github.malczuuu"
10+
11+
if (version == "unspecified") {
12+
version = Versioning.getSnapshotVersion(rootProject.rootDir)
13+
}
14+
15+
java {
16+
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
17+
withSourcesJar()
18+
withJavadocJar()
19+
}
20+
21+
repositories {
22+
mavenCentral()
23+
}
24+
25+
dependencies {
26+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.4")
27+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.13.4")
28+
29+
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.13.4")
30+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.13.4")
31+
}
32+
33+
publishing {
34+
publications {
35+
create<MavenPublication>("maven") {
36+
groupId = project.group.toString()
37+
artifactId = project.name
38+
version = project.version.toString()
39+
from(components["java"])
40+
41+
pom {
42+
name.set(project.name)
43+
description.set("Core library implementing RFC7807")
44+
url.set("https://github.com/malczuuu/${project.name}")
45+
licenses {
46+
license {
47+
name.set("MIT License")
48+
url.set("https://opensource.org/licenses/MIT")
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
spotless {
57+
format("misc") {
58+
target("*.gradle.kts", ".gitattributes", ".gitignore")
59+
60+
trimTrailingWhitespace()
61+
leadingTabsToSpaces(4)
62+
endWithNewline()
63+
lineEndings = LineEnding.UNIX
64+
}
65+
66+
java {
67+
target("src/**/*.java")
68+
69+
googleJavaFormat("1.28.0")
70+
lineEndings = LineEnding.UNIX
71+
}
72+
}
73+
74+
tasks.register("printVersion") {
75+
doLast {
76+
println("Project version: $version")
77+
}
78+
}
79+
80+
tasks.withType<JavaCompile>().configureEach {
81+
options.compilerArgs.add("-parameters")
82+
}
83+
84+
/**
85+
* Disable doclint to avoid errors and warnings on missing JavaDoc comments.
86+
*/
87+
tasks.withType<Javadoc>().configureEach {
88+
(options as StandardJavadocDocletOptions).apply {
89+
addStringOption("Xdoclint:none", "-quiet")
90+
}
91+
}
92+
93+
tasks.withType<Test>().configureEach {
94+
useJUnitPlatform()
95+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "groovy"
2+
`kotlin-dsl`
33
}
44

55
repositories {
@@ -8,5 +8,4 @@ repositories {
88

99
dependencies {
1010
implementation("org.eclipse.jgit:org.eclipse.jgit:7.3.0.202506031305-r")
11-
implementation(localGroovy())
12-
}
11+
}

buildSrc/src/main/groovy/Versioning.groovy

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import org.eclipse.jgit.revwalk.RevCommit
2+
import org.eclipse.jgit.revwalk.RevWalk
3+
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
4+
import java.io.File
5+
6+
object Versioning {
7+
8+
private const val UNSPECIFIED = "unspecified"
9+
10+
/**
11+
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD.
12+
* On error, returns "unspecified".
13+
*
14+
* @param projectRootDir the root directory of the project (containing .git)
15+
*/
16+
fun getSnapshotVersion(projectRootDir: File): String {
17+
return try {
18+
val builder = FileRepositoryBuilder()
19+
.setGitDir(File(projectRootDir, ".git"))
20+
.readEnvironment()
21+
.findGitDir()
22+
23+
builder.build().use { repository ->
24+
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
25+
26+
RevWalk(repository).use { revWalk ->
27+
val headCommit: RevCommit = revWalk.parseCommit(headId)
28+
headCommit.id.name.substring(0, 7)
29+
}
30+
}
31+
} catch (e: Exception) {
32+
System.err.println("Error determining version: $e")
33+
UNSPECIFIED
34+
}
35+
}
36+
}
File renamed without changes.

0 commit comments

Comments
 (0)