'Run scalafmtCheck in an sbt assembly

I would like to run a scalafmtCheck in sbt assembly. I tried to add:

(compile in Compile) := ((compile in Compile) dependsOn scalafmtCheck).value

I got that error :

[error] References to undefined settings: 
[error] 
[error]   submissions / scalafmtCheck from submissions / Compile / compile (/home/yass/Documents/Invenis/iss/build.sbt:45)
[error]      Did you mean submissions / Compile / scalafmtCheck ?
[error] 
[error]   scalafmtCheck from Compile / compile (/home/yass/Documents/Invenis/iss/build.sbt:45)
[error]      Did you mean Compile / scalafmtCheck ?
[error]

Any idea ?



Solution 1:[1]

You were almost there. scalafmtCheck is a task as well, therefore needs scope. What you need to do is:

Compile / compile := (Compile / compile).dependsOn(Compile / scalafmtCheck).value

If you want to add it to the assembly stage, you can do:

assembly := assembly.dependsOn(Compile / scalafmtCheck).value

If you want the format to apply this to your tests as well you can do:

Compile / compile := (Compile / compile).dependsOn(Test / scalafmtCheck).value

Or only at the assembly stage:

assembly := assembly.dependsOn(Test / scalafmtCheck).value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1