Skip to content

Commit f233a78

Browse files
committed
Give some love to the project
- Remove sbt 1.0.0 support - Update Scala version - Update sbt and sbt plugins - Remove deprecated sbt syntax usages - Update Scalafix and improve its configuration - Install Scala Steward to help us maintain this project - Fix Scalafix issues in code
1 parent 40a86b2 commit f233a78

File tree

6 files changed

+108
-65
lines changed

6 files changed

+108
-65
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Scala Steward
2+
3+
# This workflow will launch everyday at 00:00
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
workflow_dispatch: {}
8+
9+
jobs:
10+
scala-steward:
11+
timeout-minutes: 30
12+
runs-on: ubuntu-latest
13+
name: Scala Steward
14+
steps:
15+
- name: Scala Steward
16+
uses: scala-steward-org/scala-steward-action@v2.59.0

.scalafix.conf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
rules = [
2-
OrganizeImports,
2+
DisableSyntax
3+
ExplicitResultTypes
4+
LeakingImplicitClassVal
5+
NoAutoTupling
6+
NoValInForComprehension
7+
ProcedureSyntax
8+
RemoveUnused
9+
OrganizeImports
310
]
411

12+
RemoveUnused {
13+
imports = false // See https://github.com/scalacenter/scalafix/blob/v0.11.0/docs/rules/OrganizeImports.md#configuration
14+
}
15+
16+
Disable {
17+
ifSynthetic = [
18+
"scala/Option.option2Iterable"
19+
"scala/Predef.any2stringadd"
20+
]
21+
}
22+
23+
DisableSyntax.noReturns = true
24+
DisableSyntax.noXml = true
25+
DisableSyntax.noFinalize = true
26+
DisableSyntax.noValPatterns = true
27+
528
ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false
629

730
OrganizeImports.groupedImports = Explode

build.sbt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
def scala212 = "2.12.12"
1+
def scala212 = "2.12.18"
2+
3+
Global / onChangedBuildSource := ReloadOnSourceChanges
4+
25
inThisBuild(
36
List(
47
organization := "org.scalameta",
@@ -15,16 +18,14 @@ inThisBuild(
1518
)
1619
),
1720
scalaVersion := scala212,
18-
scalafixDependencies +=
19-
"com.github.liancheng" %% "organize-imports" % "0.5.0",
2021
scalacOptions ++= List("-Ywarn-unused-import"),
2122
scalafixCaching := true,
2223
semanticdbEnabled := true
2324
)
2425
)
2526

2627
crossScalaVersions := Nil
27-
skip.in(publish) := true
28+
publish / skip := true
2829

2930
commands +=
3031
Command.command("fixAll") { s =>
@@ -42,7 +43,6 @@ lazy val plugin = project
4243
.settings(
4344
moduleName := "sbt-native-image",
4445
sbtPlugin := true,
45-
sbtVersion.in(pluginCrossBuild) := "1.0.0",
4646
crossScalaVersions := List(scala212),
4747
buildInfoPackage := "sbtnativeimage",
4848
buildInfoKeys := Seq[BuildInfoKey](version),
@@ -55,8 +55,8 @@ lazy val plugin = project
5555
lazy val example = project
5656
.in(file("example"))
5757
.settings(
58-
skip.in(publish) := true,
59-
mainClass.in(Compile) := Some("example.Hello"),
58+
publish / skip := true,
59+
Compile / mainClass := Some("example.Hello"),
6060
test := {
6161
val binary = nativeImage.value
6262
val output = scala.sys.process.Process(List(binary.toString)).!!.trim

plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ object NativeImagePlugin extends AutoPlugin {
140140

141141
override lazy val projectSettings: Seq[Def.Setting[_]] = List(
142142
libraryDependencies += "org.scalameta" % "svm-subs" % "101.0.0",
143-
target.in(NativeImage) := target.in(Compile).value / "native-image",
144-
target.in(NativeImageTest) := target.in(Test).value / "native-image-test",
145-
target.in(NativeImageInternal) :=
146-
target.in(Compile).value / "native-image-internal",
147-
target.in(NativeImageTestInternal) :=
148-
target.in(Test).value / "native-image-test-internal",
143+
NativeImage / target :=
144+
(Compile / target).value / "native-image",
145+
NativeImageTest / target :=
146+
(Test / target).value / "native-image-test",
147+
NativeImageInternal / target :=
148+
(Compile / target).value / "native-image-internal",
149+
NativeImageTestInternal / target :=
150+
(Test / target).value / "native-image-test-internal",
149151
nativeImageReady := {
150152
val s = streams.value
151153

@@ -163,15 +165,18 @@ object NativeImagePlugin extends AutoPlugin {
163165
nativeImageJvm := "graalvm-java11",
164166
nativeImageJvmIndex := "cs",
165167
nativeImageVersion := "20.2.0",
166-
name.in(NativeImage) := name.value,
167-
name.in(NativeImageTest) := name.in(Test).value,
168-
mainClass.in(NativeImage) := mainClass.in(Compile).value,
169-
mainClass.in(NativeImageTest) := mainClass.in(Test).value,
170-
nativeImageOptions := List(),
168+
NativeImage / name := name.value,
169+
NativeImageTest / name :=
170+
(Test / name).value,
171+
NativeImage / mainClass :=
172+
(Compile / mainClass).value,
173+
NativeImageTest / mainClass :=
174+
(Test / mainClass).value,
175+
nativeImageOptions := List.empty,
171176
nativeImageTestOptions := nativeImageOptions.value,
172-
nativeImageTestRunOptions := List(),
177+
nativeImageTestRunOptions := List.empty,
173178
nativeImageCoursier := {
174-
val dir = target.in(NativeImageInternal).value
179+
val dir = (NativeImageInternal / target).value
175180
val out = copyResource("coursier", dir)
176181
if (Properties.isWin) {
177182
copyResource("coursier.bat", dir)
@@ -282,9 +287,9 @@ object NativeImagePlugin extends AutoPlugin {
282287
s"-agentlib:native-image-agent=$agentConfig=${nativeImageAgentOutputDir.value}"
283288
val tpr = thisProjectRef.value
284289
val settings = Seq(
285-
fork in (tpr, Compile, run) := true,
286-
javaHome in (tpr, Compile, run) := Some(graalHome),
287-
javaOptions in (tpr, Compile, run) += agentOption
290+
tpr / Compile / run / fork := true,
291+
tpr / Compile / run / javaHome := Some(graalHome),
292+
tpr / Compile / run / javaOptions += agentOption
288293
)
289294
val state0 = state.value
290295
val extracted = Project.extract(state0)
@@ -297,7 +302,7 @@ object NativeImagePlugin extends AutoPlugin {
297302
arguments.mkString(" ")
298303
Project
299304
.extract(newState)
300-
.runInputTask(run in (tpr, Compile), input, newState)
305+
.runInputTask(tpr / Compile / run, input, newState)
301306
},
302307
nativeImageTestRunAgent := {
303308
val _ = nativeImageTestCommand.value
@@ -311,12 +316,12 @@ object NativeImagePlugin extends AutoPlugin {
311316
val agentOption =
312317
s"-agentlib:native-image-agent=$agentConfig=${nativeImageTestAgentOutputDir.value}"
313318

314-
val options = (javaOptions in (Test, run)).value ++ Seq(agentOption)
319+
val options = (Test / run / javaOptions).value ++ Seq(agentOption)
315320

316-
val __ = compile.in(Test).value
317-
val main = mainClass.in(NativeImageTest).value
318-
val cp = fullClasspath.in(Test).value.map(_.data)
319-
val manifest = target.in(NativeImageTestInternal).value / "manifest.jar"
321+
val __ = (Test / compile).value
322+
val main = (NativeImageTest / mainClass).value
323+
val cp = (Test / fullClasspath).value.map(_.data)
324+
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
320325
manifest.getParentFile().mkdirs()
321326
createManifestJar(manifest, cp)
322327
val nativeClasspath = manifest.absolutePath
@@ -331,7 +336,7 @@ object NativeImagePlugin extends AutoPlugin {
331336
throw new MessageOnlyException(
332337
"no mainClass is specified for tests. " +
333338
"To fix this problem, update build.sbt to include the settings " +
334-
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
339+
"`Test / mainClass := Some(\"com.MainTestClass\")`"
335340
)
336341
)
337342
command ++= nativeImageTestRunOptions.value
@@ -344,12 +349,12 @@ object NativeImagePlugin extends AutoPlugin {
344349
}
345350
},
346351
nativeImageOutput :=
347-
target.in(NativeImage).value / name.in(NativeImage).value,
352+
(NativeImage / target).value / (NativeImage / name).value,
348353
nativeImageTestOutput :=
349-
target.in(NativeImageTest).value / name.in(NativeImageTest).value,
354+
(NativeImageTest / target).value / (NativeImageTest / name).value,
350355
nativeImageCopy := {
351356
val binary = nativeImage.value
352-
val out = fileParser(baseDirectory.in(ThisBuild).value).parsed
357+
val out = fileParser((ThisBuild / baseDirectory).value).parsed
353358
Files.copy(
354359
binary.toPath(),
355360
out.toPath(),
@@ -384,17 +389,17 @@ object NativeImagePlugin extends AutoPlugin {
384389
}
385390
},
386391
nativeImage := {
387-
val _ = compile.in(Compile).value
388-
val main = mainClass.in(NativeImage).value
392+
val _ = (Compile / compile).value
393+
val main = (NativeImage / mainClass).value
389394
val binaryName = nativeImageOutput.value
390-
val cp = fullClasspath.in(Compile).value.map(_.data)
395+
val cp = (Compile / fullClasspath).value.map(_.data)
391396
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
392397
// for two reasons:
393398
// * large classpaths quickly hit on the "argument list too large"
394399
// error, especially on Windows.
395400
// * we print the full command to the console and the manifest jar makes
396401
// it more readable and easier to copy-paste.
397-
val manifest = target.in(NativeImageInternal).value / "manifest.jar"
402+
val manifest = (NativeImageInternal / target).value / "manifest.jar"
398403
manifest.getParentFile().mkdirs()
399404
createManifestJar(manifest, cp)
400405
val nativeClasspath = manifest.absolutePath
@@ -410,14 +415,14 @@ object NativeImagePlugin extends AutoPlugin {
410415
throw new MessageOnlyException(
411416
"no mainClass is specified. " +
412417
"To fix this problem, update build.sbt to include the settings " +
413-
"`mainClass.in(Compile) := Some(\"com.MainClass\")`"
418+
"`Compile / mainClass := Some(\"com.MainClass\")`"
414419
)
415420
)
416421
command += binaryName.absolutePath
417422

418423
// Start native-image linker.
419424
streams.value.log.info(command.mkString(" "))
420-
val cwd = target.in(NativeImage).value
425+
val cwd = (NativeImage / target).value
421426
cwd.mkdirs()
422427
val exit = Process(command, cwd = Some(cwd)).!
423428
if (exit != 0) {
@@ -431,17 +436,17 @@ object NativeImagePlugin extends AutoPlugin {
431436
binaryName
432437
},
433438
nativeImageTest := {
434-
val _ = compile.in(Test).value
435-
val main = mainClass.in(NativeImageTest).value
439+
val _ = (Test / compile).value
440+
val main = (NativeImageTest / mainClass).value
436441
val binaryName = nativeImageTestOutput.value
437-
val cp = fullClasspath.in(Test).value.map(_.data)
442+
val cp = (Test / fullClasspath).value.map(_.data)
438443
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
439444
// for two reasons:
440445
// * large classpaths quickly hit on the "argument list too large"
441446
// error, especially on Windows.
442447
// * we print the full command to the console and the manifest jar makes
443448
// it more readable and easier to copy-paste.
444-
val manifest = target.in(NativeImageTestInternal).value / "manifest.jar"
449+
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
445450
manifest.getParentFile().mkdirs()
446451
createManifestJar(manifest, cp)
447452
val nativeClasspath = manifest.absolutePath
@@ -457,14 +462,14 @@ object NativeImagePlugin extends AutoPlugin {
457462
throw new MessageOnlyException(
458463
"no mainClass is specified for tests. " +
459464
"To fix this problem, update build.sbt to include the settings " +
460-
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
465+
"`Test / mainClass := Some(\"com.MainTestClass\")`"
461466
)
462467
)
463468
command += binaryName.absolutePath
464469

465470
// Start native-image linker.
466471
streams.value.log.info(command.mkString(" "))
467-
val cwd = target.in(NativeImageTest).value
472+
val cwd = (NativeImageTest / target).value
468473
cwd.mkdirs()
469474
val exit = Process(command, cwd = Some(cwd)).!
470475
if (exit != 0) {
@@ -519,8 +524,7 @@ object NativeImagePlugin extends AutoPlugin {
519524
//this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target
520525
//copy dependency next to manifest as fallback
521526
case _: IllegalArgumentException =>
522-
import java.nio.file.Files
523-
import java.nio.file.StandardCopyOption
527+
import java.nio.file.{Files, StandardCopyOption}
524528
Files.copy(
525529
dependencyPath,
526530
manifestPath.resolve(path.getName),
@@ -546,15 +550,15 @@ object NativeImagePlugin extends AutoPlugin {
546550

547551
private def alertUser(streams: std.TaskStreams[_], message: String): Unit = {
548552
streams.log.info(message)
549-
if (isCI)
550-
return
551-
try {
552-
if (Properties.isMac) {
553-
Process(List("say", message)).!
553+
if (!isCI) {
554+
try {
555+
if (Properties.isMac) {
556+
Process(List("say", message)).!
557+
}
558+
// NOTE(olafur): feel free to add support for Linux/Windows.
559+
} catch {
560+
case NonFatal(_) =>
554561
}
555-
// NOTE(olafur): feel free to add support for Linux/Windows.
556-
} catch {
557-
case NonFatal(_) =>
558562
}
559563
}
560564
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.4.4
1+
sbt.version=1.9.2

project/plugins.sbt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
2-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
3-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
4-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27")
1+
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
2+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
3+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
4+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
55

66
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
77

8-
unmanagedSourceDirectories.in(Compile) +=
9-
baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" /
8+
Compile / unmanagedSourceDirectories +=
9+
(ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" /
1010
"scala"
11-
unmanagedResourceDirectories.in(Compile) +=
12-
baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" /
11+
Compile / unmanagedResourceDirectories +=
12+
(ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" /
1313
"resources"

0 commit comments

Comments
 (0)