1

I am very new to Scala and SBT

I am trying to set up the project with Scalastyle. All works fine when running from command line, however I can't find a way to define the option as indicated on the Scalastyle website http://www.scalastyle.org/sbt.html

I tried to add something like this in the plugins.sbt

val scalastyleConfigUrl = Some(url("http://www.scalastyle.org/scalastyle_config.xml"))

I am not sure how to validate if this is working; I would expect the scalastyle_config.xml to be downloaded at each compilation, obviously I am missing something.

Second part, I would like to automate scalastyle to run at each compilation/build. How can achieve that?

Thank you

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
ab_732
  • 3,639
  • 6
  • 45
  • 61

1 Answers1

4

Scalastyle Stylesheet Download

The Stylesheet will only be downloaded once every 24 hours in the default configuration and stored in scalastyleConfigUrlCacheFile.

See documentation :

scalastyleConfigRefreshHours |  Integer |   If scalastyleConfigUrl is set, refresh it after this number of hours. Default value is 24.

Example to use remote stylesheet in compile

Setting config url in build.sbt

(scalastyleConfigUrl in Compile) := Some(url("http://www.scalastyle.org/scalastyle_config.xml"))

Run on every compile, by hand

Easy solution would be to run it by triggering it with sbt or activator

sbt scalastyle compile

Redefine compile to run scalastyle

in build.sbt

compile <<= (compile in Compile).dependsOn((scalastyle in Compile).toTask(""))

You can also override the task definition or define a custom task: http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Tasks.html#modifying-an-existing-task

Community
  • 1
  • 1
Andreas Neumann
  • 10,734
  • 1
  • 32
  • 52
  • wow that works :) do you think any way to have the command integrated with Intellij's compile? – ab_732 Nov 03 '15 at 19:23
  • one more thing: if I run `sbt compile` I would expect it to download the `scalastyle_config.xml` file - it actually fails saying "config does not exist: scalastyle-config.xml" – ab_732 Nov 03 '15 at 19:30
  • if you give no remote url you have to run `sbt scalastyle-generate-config`. – Andreas Neumann Nov 03 '15 at 19:33
  • there was a intellij plugin to run sbt tasks but i am not sure about the state it is in now – Andreas Neumann Nov 03 '15 at 19:39
  • I am trying to set the remote url both from command line then into the sbt with `val scalastyleConfigUrl = Some(url("http://www.scalastyle.org/scalastyle_config.xml"))` none of them seems to work – ab_732 Nov 03 '15 at 19:40
  • try `(scalastyleConfigUrl in Compile) := Some(url("http://www.scalastyle.org/scalastyle_config.xml"))`will adapt answer – Andreas Neumann Nov 03 '15 at 20:02