Skip to content

Commit e8fac8a

Browse files
committed
Give some love to the project
- 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 e8fac8a

File tree

6 files changed

+99
-62
lines changed

6 files changed

+99
-62
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: 8 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,7 @@ lazy val plugin = project
4243
.settings(
4344
moduleName := "sbt-native-image",
4445
sbtPlugin := true,
45-
sbtVersion.in(pluginCrossBuild) := "1.0.0",
46+
pluginCrossBuild / sbtVersion := "1.0.0",
4647
crossScalaVersions := List(scala212),
4748
buildInfoPackage := "sbtnativeimage",
4849
buildInfoKeys := Seq[BuildInfoKey](version),
@@ -55,8 +56,8 @@ lazy val plugin = project
5556
lazy val example = project
5657
.in(file("example"))
5758
.settings(
58-
skip.in(publish) := true,
59-
mainClass.in(Compile) := Some("example.Hello"),
59+
publish / skip := true,
60+
Compile / mainClass := Some("example.Hello"),
6061
test := {
6162
val binary = nativeImage.value
6263
val output = scala.sys.process.Process(List(binary.toString)).!!.trim

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

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ 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 := (Compile / target).value / "native-image",
144+
NativeImageTest / target := (Test / target).value / "native-image-test",
145+
NativeImageInternal / target := (Compile / target).value / "native-image-internal",
146+
NativeImageTestInternal / target := (Test / target).value / "native-image-test-internal",
149147
nativeImageReady := {
150148
val s = streams.value
151149

@@ -163,15 +161,15 @@ object NativeImagePlugin extends AutoPlugin {
163161
nativeImageJvm := "graalvm-java11",
164162
nativeImageJvmIndex := "cs",
165163
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(),
164+
NativeImage / name := name.value,
165+
NativeImageTest / name := (Test / name).value,
166+
NativeImage / mainClass := (Compile / mainClass).value,
167+
NativeImageTest / mainClass := (Test / mainClass).value,
168+
nativeImageOptions := List.empty,
171169
nativeImageTestOptions := nativeImageOptions.value,
172-
nativeImageTestRunOptions := List(),
170+
nativeImageTestRunOptions := List.empty,
173171
nativeImageCoursier := {
174-
val dir = target.in(NativeImageInternal).value
172+
val dir = (NativeImageInternal / target).value
175173
val out = copyResource("coursier", dir)
176174
if (Properties.isWin) {
177175
copyResource("coursier.bat", dir)
@@ -297,7 +295,7 @@ object NativeImagePlugin extends AutoPlugin {
297295
arguments.mkString(" ")
298296
Project
299297
.extract(newState)
300-
.runInputTask(run in (tpr, Compile), input, newState)
298+
.runInputTask(tpr / Compile / run, input, newState)
301299
},
302300
nativeImageTestRunAgent := {
303301
val _ = nativeImageTestCommand.value
@@ -313,11 +311,11 @@ object NativeImagePlugin extends AutoPlugin {
313311

314312
val options = (javaOptions in (Test, run)).value ++ Seq(agentOption)
315313

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"
320-
manifest.getParentFile().mkdirs()
314+
val __ = (Test / compile).value
315+
val main = (NativeImageTest / mainClass).value
316+
val cp = (Test / fullClasspath).value.map(_.data)
317+
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
318+
manifest.getParentFile.mkdirs()
321319
createManifestJar(manifest, cp)
322320
val nativeClasspath = manifest.absolutePath
323321

@@ -331,7 +329,7 @@ object NativeImagePlugin extends AutoPlugin {
331329
throw new MessageOnlyException(
332330
"no mainClass is specified for tests. " +
333331
"To fix this problem, update build.sbt to include the settings " +
334-
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
332+
"`Test / mainClass := Some(\"com.MainTestClass\")`"
335333
)
336334
)
337335
command ++= nativeImageTestRunOptions.value
@@ -344,12 +342,12 @@ object NativeImagePlugin extends AutoPlugin {
344342
}
345343
},
346344
nativeImageOutput :=
347-
target.in(NativeImage).value / name.in(NativeImage).value,
345+
(NativeImage / target).value / (NativeImage / name).value,
348346
nativeImageTestOutput :=
349-
target.in(NativeImageTest).value / name.in(NativeImageTest).value,
347+
(NativeImageTest / target).value / (NativeImageTest / name).value,
350348
nativeImageCopy := {
351349
val binary = nativeImage.value
352-
val out = fileParser(baseDirectory.in(ThisBuild).value).parsed
350+
val out = fileParser((ThisBuild / baseDirectory).value).parsed
353351
Files.copy(
354352
binary.toPath(),
355353
out.toPath(),
@@ -384,17 +382,17 @@ object NativeImagePlugin extends AutoPlugin {
384382
}
385383
},
386384
nativeImage := {
387-
val _ = compile.in(Compile).value
388-
val main = mainClass.in(NativeImage).value
385+
val _ = (Compile / compile).value
386+
val main = (NativeImage / mainClass).value
389387
val binaryName = nativeImageOutput.value
390-
val cp = fullClasspath.in(Compile).value.map(_.data)
388+
val cp = (Compile / fullClasspath).value.map(_.data)
391389
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
392390
// for two reasons:
393391
// * large classpaths quickly hit on the "argument list too large"
394392
// error, especially on Windows.
395393
// * we print the full command to the console and the manifest jar makes
396394
// it more readable and easier to copy-paste.
397-
val manifest = target.in(NativeImageInternal).value / "manifest.jar"
395+
val manifest = (NativeImageInternal / target).value / "manifest.jar"
398396
manifest.getParentFile().mkdirs()
399397
createManifestJar(manifest, cp)
400398
val nativeClasspath = manifest.absolutePath
@@ -410,14 +408,14 @@ object NativeImagePlugin extends AutoPlugin {
410408
throw new MessageOnlyException(
411409
"no mainClass is specified. " +
412410
"To fix this problem, update build.sbt to include the settings " +
413-
"`mainClass.in(Compile) := Some(\"com.MainClass\")`"
411+
"`Compile / mainClass := Some(\"com.MainClass\")`"
414412
)
415413
)
416414
command += binaryName.absolutePath
417415

418416
// Start native-image linker.
419417
streams.value.log.info(command.mkString(" "))
420-
val cwd = target.in(NativeImage).value
418+
val cwd = (NativeImage / target).value
421419
cwd.mkdirs()
422420
val exit = Process(command, cwd = Some(cwd)).!
423421
if (exit != 0) {
@@ -431,17 +429,17 @@ object NativeImagePlugin extends AutoPlugin {
431429
binaryName
432430
},
433431
nativeImageTest := {
434-
val _ = compile.in(Test).value
435-
val main = mainClass.in(NativeImageTest).value
432+
val _ = (Test / compile).value
433+
val main = (NativeImageTest / mainClass).value
436434
val binaryName = nativeImageTestOutput.value
437-
val cp = fullClasspath.in(Test).value.map(_.data)
435+
val cp = (Test / fullClasspath).value.map(_.data)
438436
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
439437
// for two reasons:
440438
// * large classpaths quickly hit on the "argument list too large"
441439
// error, especially on Windows.
442440
// * we print the full command to the console and the manifest jar makes
443441
// it more readable and easier to copy-paste.
444-
val manifest = target.in(NativeImageTestInternal).value / "manifest.jar"
442+
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
445443
manifest.getParentFile().mkdirs()
446444
createManifestJar(manifest, cp)
447445
val nativeClasspath = manifest.absolutePath
@@ -457,14 +455,14 @@ object NativeImagePlugin extends AutoPlugin {
457455
throw new MessageOnlyException(
458456
"no mainClass is specified for tests. " +
459457
"To fix this problem, update build.sbt to include the settings " +
460-
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
458+
"`Test / mainClass := Some(\"com.MainTestClass\")`"
461459
)
462460
)
463461
command += binaryName.absolutePath
464462

465463
// Start native-image linker.
466464
streams.value.log.info(command.mkString(" "))
467-
val cwd = target.in(NativeImageTest).value
465+
val cwd = (NativeImageTest / target).value
468466
cwd.mkdirs()
469467
val exit = Process(command, cwd = Some(cwd)).!
470468
if (exit != 0) {
@@ -519,8 +517,7 @@ object NativeImagePlugin extends AutoPlugin {
519517
//this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target
520518
//copy dependency next to manifest as fallback
521519
case _: IllegalArgumentException =>
522-
import java.nio.file.Files
523-
import java.nio.file.StandardCopyOption
520+
import java.nio.file.{Files, StandardCopyOption}
524521
Files.copy(
525522
dependencyPath,
526523
manifestPath.resolve(path.getName),
@@ -546,15 +543,15 @@ object NativeImagePlugin extends AutoPlugin {
546543

547544
private def alertUser(streams: std.TaskStreams[_], message: String): Unit = {
548545
streams.log.info(message)
549-
if (isCI)
550-
return
551-
try {
552-
if (Properties.isMac) {
553-
Process(List("say", message)).!
546+
if (!isCI) {
547+
try {
548+
if (Properties.isMac) {
549+
Process(List("say", message)).!
550+
}
551+
// NOTE(olafur): feel free to add support for Linux/Windows.
552+
} catch {
553+
case NonFatal(_) =>
554554
}
555-
// NOTE(olafur): feel free to add support for Linux/Windows.
556-
} catch {
557-
case NonFatal(_) =>
558555
}
559556
}
560557
}

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)