1

I have an AutoPlugin which aggregates several third-party plugins and customizes their settings for our company. For most of the plugins, this works just fine by putting them in the projectSettings:

override lazy val projectSettings = Seq( somePluginSetting := "whatever" )

I tried to do this for ScalaStyle as well:

import org.scalastyle.sbt.ScalastylePlugin.scalastyleConfigUrl

override lazy val projectSettings = Seq(
  scalastyleConfigUrl := Some(url("http://git.repo/scalastyle-config.xml"))
)

This setting is never visible in projects using my plugin, instead sbt uses the plugin-provided default value:

> inspect scalastyleConfigUrl
[info] Setting: scala.Option[java.net.URL] = None
[info] Description:
[info]  Scalastyle configuration file as a URL
[info] Provided by:
[info]  {file:/Users/kaeser/Documents/workspace/ci-test-project/}root/*:scalastyleConfigUrl
[info] Defined at:
[info]  (org.scalastyle.sbt.ScalastylePlugin) Plugin.scala:101
[info] Delegates:
[info]  *:scalastyleConfigUrl
[info]  {.}/*:scalastyleConfigUrl
[info]  */*:scalastyleConfigUrl
[info] Related:
[info]  test:scalastyleConfigUrl

When I put the setting into build.sbt directly, it works as expected.

I made a simple example sbt plugin that shows the problem: https://github.com/jastice/sbt-customsettings

What might the issue be?

Justin Kaeser
  • 5,868
  • 27
  • 46
  • 1
    Can you give a project which worked before and no longer works? – Matthew Farwell Oct 21 '14 at 19:44
  • I'll try to create a minimal project showing the problem – Justin Kaeser Oct 22 '14 at 06:34
  • updated with link to example project – Justin Kaeser Oct 22 '14 at 09:31
  • Did this work with 0.5.0? – Matthew Farwell Oct 22 '14 at 12:05
  • I haven't tried with 0.5.0, since that version didn't play well with some of our projects, but I can try it with the example project tomorrow. – Justin Kaeser Oct 22 '14 at 16:09
  • 2
    Fun story... I was the guy who wrote the `scalastyleConfigUrl` change. Anyway we had a reason at our company that we couldn't actually use my changes until today... I found out that the plugin got refactored some since I made the change so not only is the README out of date but also I couldn't get the setting to work. I was at my wits' end and was searching github for people using my feature and I found your repo. Small world. I "fixed" the problem by using the `in Compile` scope for now. – 2rs2ts Jan 14 '15 at 00:26

1 Answers1

3

This problem is most likely caused by the order in which settings are applied. If your plugin and the plugin you are depending on are both autoplugins, the requires value determines the order in which project settings are included.

Scalastyle still uses the old plugin format. It also does not follow the best practices. It should not set projectSettings as that makes it difficult to disable it in multi project builds. And it also prevents you from easily extending it from your custom plugin. I am not sure if the order in which project settings are applied is defined, or is determined by the order in which the plugins are loaded.

The easiest fix would be to make Scalastyle an AutoPlugin and depend on it using the requires value. Otherwise it's probably quite tricky to find out what determines the order.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • 1
    For my case, I could fix the problem by simply setting `scalastyleConfigUrl in Compile` -- this one isn't overwritten by ScalaStyle. However, the `in Test` version is, so it's not a complete solution. I will probably try making ScalaStyle a proper AutoPlugin and see how that works out. – Justin Kaeser Oct 28 '14 at 15:06