Skip to content

Commit f1b7eb7

Browse files
committed
Apply formatting for *.kt and *.gradle.kts
1 parent 2ab5b27 commit f1b7eb7

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

build.gradle.kts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ group = "io.github.malczuuu.problem4j"
1515
* -Pversion={releaseVersion} parameter to match Git tag.
1616
*/
1717
version =
18-
if (version == "unspecified")
18+
if (version == "unspecified") {
1919
getSnapshotVersion(rootProject.rootDir)
20-
else
20+
} else {
2121
version
22+
}
2223

2324
java {
2425
toolchain.languageVersion = JavaLanguageVersion.of(8)
@@ -80,7 +81,7 @@ publishing {
8081
}
8182

8283
nmcp {
83-
publishAllPublicationsToCentralPortal {
84+
publishAllPublicationsToCentralPortal {
8485
username = System.getenv("PUBLISHING_USERNAME")
8586
password = System.getenv("PUBLISHING_PASSWORD")
8687

@@ -92,7 +93,7 @@ signing {
9293
if (project.hasProperty("sign")) {
9394
useInMemoryPgpKeys(
9495
System.getenv("SIGNING_KEY"),
95-
System.getenv("SIGNING_PASSWORD")
96+
System.getenv("SIGNING_PASSWORD"),
9697
)
9798
sign(publishing.publications["maven"])
9899
}
@@ -115,6 +116,22 @@ spotless {
115116
googleJavaFormat("1.28.0")
116117
lineEndings = LineEnding.UNIX
117118
}
119+
120+
kotlin {
121+
target("**/src/**/*.kt")
122+
123+
ktfmt("0.59").metaStyle()
124+
endWithNewline()
125+
lineEndings = LineEnding.UNIX
126+
}
127+
128+
kotlinGradle {
129+
target("**/*.gradle.kts")
130+
131+
ktlint()
132+
endWithNewline()
133+
lineEndings = LineEnding.UNIX
134+
}
118135
}
119136

120137
/**
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1+
import java.io.File
12
import org.eclipse.jgit.revwalk.RevCommit
23
import org.eclipse.jgit.revwalk.RevWalk
34
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
4-
import java.io.File
55

66
private const val UNSPECIFIED = "unspecified"
77

88
/**
9-
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD.
10-
* On error, returns "unspecified".
9+
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD. On error,
10+
* returns "unspecified".
1111
*
1212
* @param projectRootDir the root directory of the project (containing .git)
1313
*/
1414
fun getSnapshotVersion(projectRootDir: File): String {
15-
return try {
16-
val builder = FileRepositoryBuilder()
15+
return try {
16+
val builder =
17+
FileRepositoryBuilder()
1718
.setGitDir(File(projectRootDir, ".git"))
1819
.readEnvironment()
1920
.findGitDir()
2021

21-
builder.build().use { repository ->
22-
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
22+
builder.build().use { repository ->
23+
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
2324

24-
RevWalk(repository).use { revWalk ->
25-
val headCommit: RevCommit = revWalk.parseCommit(headId)
26-
headCommit.id.name.substring(0, 7)
27-
}
28-
}
29-
} catch (e: Exception) {
30-
System.err.println("Error determining version: $e")
31-
UNSPECIFIED
25+
RevWalk(repository).use { revWalk ->
26+
val headCommit: RevCommit = revWalk.parseCommit(headId)
27+
headCommit.id.name.substring(0, 7)
28+
}
3229
}
30+
} catch (e: Exception) {
31+
System.err.println("Error determining version: $e")
32+
UNSPECIFIED
33+
}
3334
}

0 commit comments

Comments
 (0)