From 5880888fb58ef1e4fc752809f29bcd7d4fdf713c Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 17:17:50 +0400 Subject: [PATCH] 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 --- .github/workflows/scala-steward.yml | 16 ++++++++++++ .scalafix.conf | 25 ++++++++++++++++++- build.sbt | 15 +++++------ .../sbtnativeimage/NativeImagePlugin.scala | 19 +++++++------- project/build.properties | 2 +- project/plugins.sbt | 16 ++++++------ 6 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/scala-steward.yml diff --git a/.github/workflows/scala-steward.yml b/.github/workflows/scala-steward.yml new file mode 100644 index 0000000..83edb99 --- /dev/null +++ b/.github/workflows/scala-steward.yml @@ -0,0 +1,16 @@ +name: Scala Steward + +# This workflow will launch everyday at 00:00 +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: {} + +jobs: + scala-steward: + timeout-minutes: 30 + runs-on: ubuntu-latest + name: Scala Steward + steps: + - name: Scala Steward + uses: scala-steward-org/scala-steward-action@v2.59.0 diff --git a/.scalafix.conf b/.scalafix.conf index b6b7aab..84a4444 100644 --- a/.scalafix.conf +++ b/.scalafix.conf @@ -1,7 +1,30 @@ rules = [ - OrganizeImports, + DisableSyntax + ExplicitResultTypes + LeakingImplicitClassVal + NoAutoTupling + NoValInForComprehension + ProcedureSyntax + RemoveUnused + OrganizeImports ] +RemoveUnused { + imports = false // See https://github.com/scalacenter/scalafix/blob/v0.11.0/docs/rules/OrganizeImports.md#configuration +} + +Disable { + ifSynthetic = [ + "scala/Option.option2Iterable" + "scala/Predef.any2stringadd" + ] +} + +DisableSyntax.noReturns = true +DisableSyntax.noXml = true +DisableSyntax.noFinalize = true +DisableSyntax.noValPatterns = true + ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false OrganizeImports.groupedImports = Explode diff --git a/build.sbt b/build.sbt index c8a40c7..10191d4 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,7 @@ -def scala212 = "2.12.12" +def scala212 = "2.12.18" + +Global / onChangedBuildSource := ReloadOnSourceChanges + inThisBuild( List( organization := "org.scalameta", @@ -15,8 +18,6 @@ inThisBuild( ) ), scalaVersion := scala212, - scalafixDependencies += - "com.github.liancheng" %% "organize-imports" % "0.5.0", scalacOptions ++= List("-Ywarn-unused-import"), scalafixCaching := true, semanticdbEnabled := true @@ -24,7 +25,7 @@ inThisBuild( ) crossScalaVersions := Nil -skip.in(publish) := true +publish / skip := true commands += Command.command("fixAll") { s => @@ -42,7 +43,7 @@ lazy val plugin = project .settings( moduleName := "sbt-native-image", sbtPlugin := true, - sbtVersion.in(pluginCrossBuild) := "1.0.0", + pluginCrossBuild / sbtVersion := "1.0.0", crossScalaVersions := List(scala212), buildInfoPackage := "sbtnativeimage", buildInfoKeys := Seq[BuildInfoKey](version), @@ -55,8 +56,8 @@ lazy val plugin = project lazy val example = project .in(file("example")) .settings( - skip.in(publish) := true, - mainClass.in(Compile) := Some("example.Hello"), + publish / skip := true, + Compile / mainClass := Some("example.Hello"), test := { val binary = nativeImage.value val output = scala.sys.process.Process(List(binary.toString)).!!.trim diff --git a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala index 815cfb9..040a556 100644 --- a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala +++ b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala @@ -519,8 +519,7 @@ object NativeImagePlugin extends AutoPlugin { //this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target //copy dependency next to manifest as fallback case _: IllegalArgumentException => - import java.nio.file.Files - import java.nio.file.StandardCopyOption + import java.nio.file.{Files, StandardCopyOption} Files.copy( dependencyPath, manifestPath.resolve(path.getName), @@ -546,15 +545,15 @@ object NativeImagePlugin extends AutoPlugin { private def alertUser(streams: std.TaskStreams[_], message: String): Unit = { streams.log.info(message) - if (isCI) - return - try { - if (Properties.isMac) { - Process(List("say", message)).! + if (!isCI) { + try { + if (Properties.isMac) { + Process(List("say", message)).! + } + // NOTE(olafur): feel free to add support for Linux/Windows. + } catch { + case NonFatal(_) => } - // NOTE(olafur): feel free to add support for Linux/Windows. - } catch { - case NonFatal(_) => } } } diff --git a/project/build.properties b/project/build.properties index 7de0a93..875b706 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.4 +sbt.version=1.9.2 diff --git a/project/plugins.sbt b/project/plugins.sbt index 96148c6..ce65de8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,13 +1,13 @@ -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0") libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value -unmanagedSourceDirectories.in(Compile) += - baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" / +Compile / unmanagedSourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" / "scala" -unmanagedResourceDirectories.in(Compile) += - baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" / +Compile / unmanagedResourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" / "resources"