scalastyle / scalastyle-sbt-plugin

scalastyle-sbt-plugin
Apache License 2.0
139 stars 52 forks source link

Setting (scalastyleConfig in Test) inside an AutoPlugin doesn't work #44

Closed jawshooah closed 7 years ago

jawshooah commented 9 years ago

I'm trying to extract shared plugins and settings into a common set of AutoPlugins. Here's the plugin for Scalastyle:

package com.jawshooah.sbt

import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin

import org.scalastyle.sbt.ScalastylePlugin
import org.scalastyle.sbt.ScalastylePlugin._

object ScalastylePluginSettings extends AutoPlugin {
  override def requires = JvmPlugin
  override def trigger = allRequirements

  /* ScalastylePlugin is not an AutoPlugin, so we manually add its settings here */
  override def projectSettings =
    ScalastylePlugin.projectSettings ++
    baseSettings ++
    Project.inConfig(Compile)(baseSettings) ++
    Project.inConfig(Test)(baseSettings)

  lazy val baseSettings = Seq(
    (scalastyleConfig in Compile) := sbtCommonDir.value / "scalastyle-config.xml",
    (scalastyleConfig in Test) := sbtCommonDir.value / "scalastyle-test-config.xml"
  )

  lazy val sbtCommonDir = baseDirectory { _ / "project" / "sbt-common" }
}

scalastyleConfig appears to be set correctly in Compile:

> inspect compile:scalastyleConfig
[info] Setting: java.io.File = /Users/joshuahagins/dev/sandbox/sbt-common-test/project/sbt-common/scalastyle-config.xml
[info] Description:
[info]  Scalastyle configuration file
[info] Provided by:
[info]  {file:/Users/joshuahagins/dev/sandbox/sbt-common-test/}root/compile:scalastyleConfig
[info] Defined at:
[info]  (com.jawshooah.sbt.ScalastylePluginSettings) ScalastylePluginSettings.scala:22
[info] Dependencies:
[info]  compile:baseDirectory
[info] Reverse dependencies:
[info]  compile:scalastyleGenerateConfig
[info]  compile:scalastyle
[info] Delegates:
[info]  compile:scalastyleConfig
[info]  *:scalastyleConfig
[info]  {.}/compile:scalastyleConfig
[info]  {.}/*:scalastyleConfig
[info]  */compile:scalastyleConfig
[info]  */*:scalastyleConfig
[info] Related:
[info]  *:scalastyle::scalastyleConfig
[info]  test:scalastyle::scalastyleConfig
[info]  test:scalastyleConfig
[info]  compile:scalastyle::scalastyleConfig
[info]  *:scalastyleConfig

...but not in Test:

> inspect test:scalastyleConfig
[info] Setting: java.io.File = scalastyle-config.xml
[info] Description:
[info]  Scalastyle configuration file
[info] Provided by:
[info]  {file:/Users/joshuahagins/dev/sandbox/sbt-common-test/}root/test:scalastyleConfig
[info] Defined at:
[info]  (org.scalastyle.sbt.ScalastylePlugin) Plugin.scala:100
[info] Dependencies:
[info]  *:scalastyle::scalastyleConfig
[info] Reverse dependencies:
[info]  test:scalastyleGenerateConfig
[info]  test:scalastyle
[info] Delegates:
[info]  test:scalastyleConfig
[info]  runtime:scalastyleConfig
[info]  compile:scalastyleConfig
[info]  *:scalastyleConfig
[info]  {.}/test:scalastyleConfig
[info]  {.}/runtime:scalastyleConfig
[info]  {.}/compile:scalastyleConfig
[info]  {.}/*:scalastyleConfig
[info]  */test:scalastyleConfig
[info]  */runtime:scalastyleConfig
[info]  */compile:scalastyleConfig
[info]  */*:scalastyleConfig
[info] Related:
[info]  compile:scalastyleConfig
[info]  *:scalastyleConfig

If I add the line:

(scalastyleConfig in scalastyle) := sbtCommonDir.value / "scalastyle-test-config.xml"

...it works. I assume this is related to the way scalastyleConfig in Test is initially set, but this is very counterintuitive, and I'm not sure if it has any other repercussions.

jawshooah commented 9 years ago

I've created an example repository at jawshooah/sbt-scalastyle-autoplugin-test to demonstrate how to reproduce this issue.

jawshooah commented 8 years ago

Note that the same problem appears to be present when setting scalastyleTarget in Test, except that additionally setting scalastyleTarget in scalastyle doesn't work here.

jawshooah commented 8 years ago

@matthewfarwell Any input on this?

edmondop commented 8 years ago

+1

aggenebbisj commented 7 years ago

+1

er1c commented 7 years ago

+1

amuttsch commented 7 years ago

Was anyone able to set scalastyleConfigUrl in Test? The trick with in scalastyle doesn't work for scalastyleConfigUrl.

matthewfarwell commented 7 years ago

This is probably fixed now, via #52. Can you test it against the 0.9.0-SNAPSHOT and see if it works please?