Skip to content

Commit 50fdf67

Browse files
committed
Add Scala3 support - and copy over some code as proof (#234)
Related => will-molloy/java-template#246 GitOrigin-RevId: 3ee4f8dae33f7065d3d911814574ef6296496542
1 parent 87b5eac commit 50fdf67

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

build.gradle.kts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import com.github.spotbugs.snom.SpotBugsExtension
55
import com.github.spotbugs.snom.SpotBugsTask
66
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
77
import org.gradle.api.tasks.testing.logging.TestLogEvent
8-
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
98

109
logger.quiet("Java version: ${JavaVersion.current()}")
1110
logger.quiet("Gradle version: ${gradle.gradleVersion}")
1211

1312
plugins {
1413
id("java-library")
15-
kotlin("jvm") version libs.versions.kotlin
1614
alias(libs.plugins.spotless)
1715
alias(libs.plugins.spotbugs)
1816
alias(libs.plugins.buildtimetracker)
@@ -30,11 +28,6 @@ allprojects {
3028
targetCompatibility = JavaVersion.VERSION_21
3129
}
3230

33-
apply(plugin = "kotlin")
34-
configure<KotlinJvmProjectExtension> {
35-
jvmToolchain(21)
36-
}
37-
3831
apply(plugin = "com.diffplug.spotless")
3932
configure<SpotlessExtension> {
4033
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#java
@@ -45,9 +38,6 @@ allprojects {
4538
endWithNewline()
4639
}
4740
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#kotlin
48-
// Compared to ktlint, it seems ktfmt is better for actual Kotlin code (more deterministic/consistent output).
49-
// Furthermore, spotless is more for formatting than linting.
50-
// However, it has some weird output with Gradle scripts, so using ktlint for that.
5141
kotlin {
5242
ktfmt().googleStyle()
5343
trimTrailingWhitespace()
@@ -58,9 +48,15 @@ allprojects {
5848
trimTrailingWhitespace()
5949
endWithNewline()
6050
}
51+
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#scala
52+
scala {
53+
scalafmt().configFile("$rootDir/scalafmt.conf")
54+
trimTrailingWhitespace()
55+
endWithNewline()
56+
}
6157
}
6258

63-
// TODO Kotlin alternative?
59+
// TODO Kotlin/Scala alternative?
6460
apply(plugin = "checkstyle")
6561
configure<CheckstyleExtension> {
6662
toolVersion = "10.12.0"
@@ -114,17 +110,6 @@ allprojects {
114110
}
115111
}
116112

117-
val previewFeatures = emptyList<String>()
118-
tasks.withType<JavaCompile> {
119-
options.compilerArgs = previewFeatures
120-
}
121-
tasks.withType<Test> {
122-
jvmArgs = previewFeatures
123-
}
124-
tasks.withType<JavaExec> {
125-
jvmArgs = previewFeatures
126-
}
127-
128113
dependencies {
129114
implementation(rootProject.libs.spotbugs.annotations)
130115

gradle/libs.versions.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ spotbugs = { id = "com.github.spotbugs", version = "6.0.27" }
44
buildtimetracker = { id = "com.asarkar.gradle.build-time-tracker", version = "4.3.0" }
55

66
[versions]
7-
kotlin = "2.1.0"
8-
log4j = "2.24.3"
97
spotbugs = "4.8.6"
108
guava = "33.4.0-jre"
9+
log4j = "2.24.3"
1110
commons-lang = "3.17.0"
1211
jackson = "2.18.2"
1312
# test libs
1413
junit = "5.11.4"
1514
truth = "1.4.4"
1615
mockito = "5.14.2"
16+
# langs
17+
scala = "3.6.2"
18+
kotlin = "2.1.0"
1719

1820
[libraries]
1921
spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version.ref = "spotbugs" }
@@ -29,3 +31,5 @@ truth = { module = "com.google.truth:truth", version.ref = "truth" }
2931
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
3032
mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }
3133
guava-testlib = { module = "com.google.guava:guava-testlib", version.ref = "guava" }
34+
# scala
35+
scala-library = { module = "org.scala-lang:scala3-library_3", version.ref = "scala" }

scalafmt.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version = "3.7.3"
2+
runner.dialect = scala3
3+
maxColumn = 100
4+
docstrings.style = Asterisk

spotbugs-exclude.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<FindBugsFilter>
3-
<Match>
4-
<!-- kotlin -->
5-
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
6-
</Match>
73
</FindBugsFilter>

0 commit comments

Comments
 (0)