ngbinh / gradle-scalastyle-plugin

Gradle plugin for scalastyle
18 stars 16 forks source link

Discover sourceSets automatically that have scala sources and create dynamic tasks for them #45

Open olisikh opened 6 years ago

olisikh commented 6 years ago

Hello,

It's a great plugin, but I really miss some of the functionality. For example I have not only main/scala and test/scala but also integrationTest/scala and gatling/scala and I can't just run scalastyle on all of them.

Maybe we could improve the plugin so that it will create scalastyleMain, scalastyleTest, scalastyleIntegrationTest, scalastyleGatling automatically and the parent task scalastyle to run them all?

We could make an extension scalastyle using named domain object container e.g.

scalaStyle {
  // global config (use in case there is no override for specific source set)
  config = file("$rootDir/scalastyle.xml")
  // globally configure to fail on warnings
  failOnWarnings = true  

  // not sure it's the right name, or 
  // maybe even we don't need this nesting and should just handle a missing method call
  sourceSets {
    // gatling is supposed to be a DSL, 
    // so I don't really want production code checks to be run on it, 
    // but rather some basic checks and DSL specific
    gatling {
      config = file("$rootDir/scalastyle-test.xml")
    }

    test {
      // do not fail on warnings when checking test source set
      failOnWarnings = false  
    }

    garbage {
      // do not even create a task for this source set
      skip = true
    }
  }
}

Usage:

// runs main source set checks
gradlew scalaStyleMain
// error, no task for garbage source set
gradlew scalaStyleGarbage
// runs all (scalaStyleMain, scalaStyleTest)
gradlew scalaStyle 

If somebody else is interested, I can work on that. I have something similar like I proposed implemented as a plugin in buildSrc, however I made it as a JavaExec task (just running a scalastyle jar with needed arguments)

willis7 commented 5 years ago

I'm hitting the same problem with integration tests not having their own task