Skip to content

Commit 1acab77

Browse files
committed
Use scala-cli to format scala, spotless-gradle to format java
1 parent bc8b502 commit 1acab77

28 files changed

Lines changed: 155 additions & 110 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
name: Continuous Integration
22

3-
env:
4-
# https://github.com/google/google-java-format?tab=readme-ov-file#as-a-library
5-
JDK_JAVA_OPTIONS: |
6-
--add-opens=java.base/java.util=ALL-UNNAMED
7-
--add-opens=java.base/java.lang=ALL-UNNAMED
8-
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
9-
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10-
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
11-
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
12-
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
13-
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
14-
153
on:
164
pull_request:
175
branches: ["**"]
@@ -44,11 +32,12 @@ jobs:
4432
- uses: extractions/setup-just@v3
4533
- uses: sbt/setup-sbt@v1
4634
with:
47-
sbt-runner-version: 1.11.7
35+
sbt-runner-version: 1.12.0
4836
- uses: zhutmost/setup-mill@main
4937
with:
5038
mill-version: 1.1.0-RC2
5139
- uses: gradle/actions/setup-gradle@v5
40+
- uses: VirtusLab/[email protected]
5241

5342
- name: Check code formatting
5443
run: just code-format-check-all
@@ -85,7 +74,7 @@ jobs:
8574
- uses: extractions/setup-just@v3
8675
- uses: sbt/setup-sbt@v1
8776
with:
88-
sbt-runner-version: 1.11.7
77+
sbt-runner-version: 1.12.0
8978
- uses: zhutmost/setup-mill@main
9079
with:
9180
mill-version: 1.1.0-RC2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ build/
2424
metals.sbt
2525
.bloop/
2626
*.semanticdb
27+
28+
# scala-cli output
29+
.scala-build

.jvmopts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-Dfile.encoding=UTF-8
2+
-Dencoding=UTF-8
3+
--add-opens=java.base/java.util=ALL-UNNAMED
4+
--add-opens=java.base/java.lang=ALL-UNNAMED

.scalafmt.conf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
version = "3.9.9"
22
runner.dialect = scala3
33

4-
lineEndings=preserve
4+
lineEndings = preserve
55

66
rewrite.rules = [
77
Imports
88
]
99
rewrite.imports.expand = true
1010
rewrite.imports.sort = scalastyle
11+
12+
project {
13+
includePaths = [
14+
"glob:**.scala",
15+
"regex:.*\\.mill"
16+
]
17+
excludePaths = [
18+
# Ignore mill output
19+
"glob:**/out/**.scala",
20+
"glob:**/out/**.mill"
21+
]
22+
}

build.mill

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import mill.*, javalib.*, javalib.publish, scalalib.*, scalalib.publish.*
99
import mill.api.BuildCtx
1010
import mill.api.Task.Simple
1111
import mill.contrib.buildinfo.BuildInfo
12-
import mill.scalalib.scalafmt.ScalafmtModule
1312
import mill.util.BuildInfo.millBinPlatform
1413
import mill.util.BuildInfo.millVersion
1514
// @formatter:on
@@ -101,11 +100,7 @@ trait HookScalaModule
101100
)
102101
}
103102

104-
object `mill-live-reload`
105-
extends ScalaModule,
106-
CorePublishModule,
107-
BuildInfo,
108-
ScalafmtModule {
103+
object `mill-live-reload` extends ScalaModule, CorePublishModule, BuildInfo {
109104

110105
override def scalaVersion = "3.7.3"
111106

@@ -120,10 +115,6 @@ object `mill-live-reload`
120115
mvn"org.jline:jline:3.30.6"
121116
)
122117

123-
override def scalafmtConfig: T[Seq[PathRef]] = Task.Sources(
124-
BuildCtx.workspaceRoot / ".scalafmt.conf"
125-
)
126-
127118
object integration extends ScalaTests, TestModule.ScalaTest, BuildInfo {
128119

129120
override def scalaTestVersion = "3.2.19"

build.sbt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
lazy val scala212 = "2.12.20"
2-
lazy val scala213 = "2.13.16"
3-
lazy val scala3 = "3.7.2"
1+
lazy val scala212 = "2.12.21"
2+
lazy val scala213 = "2.13.18"
3+
lazy val scala3 = "3.7.4"
44
lazy val supportedScalaVersions = List(scala212, scala213, scala3)
55
lazy val supportedScalaSbtVersions = List(scala212, scala3)
66

7+
javacOptions ++= Seq("-encoding", "UTF-8")
78
scalacOptions ++= Seq(
89
"-deprecation",
910
"-feature",
1011
"-unchecked",
1112
"-encoding",
12-
"utf8"
13+
"UTF-8"
1314
) ++
1415
(CrossVersion.partialVersion(scalaVersion.value) match {
1516
case Some((2, _)) => Seq("-Xsource:3")
@@ -46,9 +47,6 @@ addCommandAlias(
4647
)
4748
addCommandAlias("quickScripted", "quickPublish;scripted")
4849

49-
addCommandAlias("fmtCheckAll", "javafmtCheckAll;scalafmtCheckAll")
50-
addCommandAlias("fmtAll", "javafmtAll;scalafmtAll")
51-
5250
// if version was pinned already, read from file, otherwise generate new
5351
version := {
5452
val versionFile = file("version.txt")
@@ -62,7 +60,8 @@ version := {
6260
lazy val javaProjectSettings = Seq(
6361
crossScalaVersions := List(scala212),
6462
crossPaths := false,
65-
autoScalaLibrary := false
63+
autoScalaLibrary := false,
64+
Compile / unmanagedSourceDirectories := (Compile / javaSource).value :: Nil
6665
)
6766

6867
LocalRootProject / name := "root"
@@ -71,16 +70,15 @@ LocalRootProject / publishLocal / skip := true
7170
LocalRootProject / publishM2 / skip := true
7271

7372
lazy val `sbt-live-reload` = (projectMatrix in file("sbt"))
74-
.enablePlugins(SbtPlugin)
75-
.enablePlugins(BuildInfoPlugin)
73+
.enablePlugins(SbtPlugin, BuildInfoPlugin)
7674
.settings(
7775
name := "sbt-live-reload",
7876
description := "Provides an universal Live Reload experience for web applications built with sbt",
7977
scriptedBufferLog := false,
8078
scriptedBatchExecution := false,
8179
(pluginCrossBuild / sbtVersion) := {
8280
scalaBinaryVersion.value match {
83-
case "2.12" => "1.11.7"
81+
case "2.12" => "1.12.0"
8482
case _ => "2.0.0-RC8"
8583
}
8684
},
@@ -89,8 +87,7 @@ lazy val `sbt-live-reload` = (projectMatrix in file("sbt"))
8987
scriptedLaunchOpts += version.apply { v => s"-Dproject.version=$v" }.value
9088
)
9189
.jvmPlatform(scalaVersions = supportedScalaSbtVersions)
92-
.dependsOn(`build-link`)
93-
.dependsOn(`runner`)
90+
.dependsOn(`build-link`, `runner`)
9491

9592
lazy val `webserver` = (project in file("core/webserver"))
9693
.settings(javaProjectSettings)
@@ -124,7 +121,11 @@ lazy val `hook-scala` = (projectMatrix in file("core/hook-scala"))
124121
libraryDependencies := Seq(
125122
Dependencies.zio % Provided,
126123
Dependencies.catsEffect % Provided
127-
)
124+
) ++ (scalaBinaryVersion.value match {
125+
// https://github.com/sbt/sbt/issues/8328
126+
case "3" => Seq("org.scala-lang" %% "scala3-library" % scalaVersion.value)
127+
case _ => Seq.empty
128+
})
128129
)
129130
.jvmPlatform(scalaVersions = supportedScalaVersions)
130131
.dependsOn(`build-link`)

buildSrc/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ plugins {
44

55
repositories {
66
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
dependencies {
11+
implementation("com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:8.0.0")
712
}

buildSrc/src/main/kotlin/core-java-library.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
plugins {
22
`java-library`
33
`maven-publish`
4+
id("com.diffplug.spotless")
45
}
56

67
group = "me.seroperson"
78
version = readVersion()
89

10+
spotless {
11+
java {
12+
googleJavaFormat()
13+
}
14+
}
15+
916
java {
1017
toolchain {
1118
languageVersion = JavaLanguageVersion.of(17)

gradle/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
`kotlin-dsl`
33
`java-gradle-plugin`
4-
id("com.diffplug.spotless") version "8.0.0"
4+
id("com.diffplug.spotless")
55
id("com.gradle.plugin-publish") version "2.0.0"
66
id("com.github.gmazzo.buildconfig") version "5.7.0"
77
}

justfile

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set shell := ["bash", "-c"]
33
gradle := "./gradlew"
44
mill := "mill"
55
sbt := "sbt"
6+
scala-cli := "scala-cli"
67

78
default: publish-local-sbt
89

@@ -57,20 +58,12 @@ publish-mill: calculate-version
5758
{{ mill }} mill-live-reload.publishSonatypeCentral
5859

5960
[private]
60-
code-format-check-sbt:
61-
{{ sbt }} fmtCheckAll
61+
code-format-check-scala:
62+
{{ scala-cli }} fmt --check
6263

6364
[private]
64-
code-format-apply-sbt:
65-
{{ sbt }} fmtAll
66-
67-
[private]
68-
code-format-check-mill:
69-
{{ mill }} mill-live-reload.checkFormat
70-
71-
[private]
72-
code-format-apply-mill:
73-
{{ mill }} mill-live-reload.reformat
65+
code-format-apply-scala:
66+
{{ scala-cli }} fmt
7467

7568
[private]
7669
code-format-check-gradle:
@@ -81,11 +74,11 @@ code-format-apply-gradle:
8174
{{ gradle }} spotlessApply
8275

8376
[doc('Checks formatting. Fails if formatting does not match style.')]
84-
code-format-check-all: code-format-check-sbt code-format-check-mill code-format-check-gradle
77+
code-format-check-all: code-format-check-scala code-format-check-gradle
8578
@echo "SUCCESS"
8679

8780
[doc('Applies formatting.')]
88-
code-format-apply-all: code-format-apply-sbt code-format-apply-mill code-format-apply-gradle
81+
code-format-apply-all: code-format-apply-scala code-format-apply-gradle
8982
@echo "SUCCESS"
9083

9184
[doc('Runs all tests.')]

0 commit comments

Comments
 (0)