Skip to content

Scalafix sbt task hangs when invoked as part of compile task #2008

Open
@bpholt

Description

Prior to Scalafix 0.12.1, we had many repos where we apply Scalafix rules on every compile by chaining the scalafix task as part of the compile task. As of 0.12.1, applying any semantic rules in this way causes sbt to hang in such a way that it can only be killed from the outside (e.g. using kill -9 ${sbt pid}).

As a minimal example, use this build.sbt:

Compile / compile := Def.taskDyn {
  val output = (Compile / compile).value
  Def.task {
    (Compile / scalafix).toTask(" ExplicitResultTypes").value
    output
  }
}.value

project/plugins.sbt:

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")

and project/build.properties:

sbt.version=1.10.0

Example output:

[info] welcome to sbt 1.10.0 (Eclipse Adoptium Java 11.0.18)
[info] loading settings for project global-plugins from global.sbt ...
[info] loading global plugins from ~/.sbt/1.0/plugins
[info] loading settings for project sbt-scalafix-issue-build from plugins.sbt ...
[info] loading project definition from ~/sbt-scalafix-issue/project
[info] loading settings for project sbt-scalafix-issue from build.sbt ...
[info] set current project to sbt-scalafix-issue (in build file:~/sbt-scalafix-issue/)
sbt:sbt-scalafix-issue> compile
^C
[warn] Canceling execution...
^Z
[1]+  Stopped                 sbt
~/sbt-scalafix-issue $ kill -9 %1
[1]+  Killed: 9               sbt

If we comment out the (Compile / scalafix).toTask(" ExplicitResultTypes").value line in build.sbt and run the tasks separately, they work fine:

[info] welcome to sbt 1.10.0 (Eclipse Adoptium Java 11.0.18)
[info] loading settings for project global-plugins from global.sbt ...
[info] loading global plugins from ~/.sbt/1.0/plugins
[info] loading settings for project sbt-scalafix-issue-build from plugins.sbt ...
[info] loading project definition from ~/sbt-scalafix-issue/project
[info] loading settings for project sbt-scalafix-issue from build.sbt ...
[info] set current project to sbt-scalafix-issue (in build file:~/sbt-scalafix-issue/)
sbt:sbt-scalafix-issue> compile
[success] Total time: 0 s, completed Jun 10, 2024, 4:56:53 PM
sbt:sbt-scalafix-issue> scalafix ExplicitResultTypes
[success] Total time: 1 s, completed Jun 10, 2024, 4:57:02 PM

Furthermore, using one of the built-in syntactic rules works fine as well.

Replacing Scalafix 0.12.1 with 0.12.0 also works fine.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions