3

I am trying to integrate Checkstyle and PMD into the Play framework. I started by using the giter8 template created by ymasory to produce a sample build.scala file that supports the checkstyle and pmd commands in the sbt console. This works fine and I've uploaded the resulting project to github:

https://github.com/ics-software-engineering/sbt-example-qa

The problem occurs when I try to use this code with the Build.scala file created by the Play new command. The giter8 template integrates checkstyle and pmd using the 'settings' value, as illustrated here (see the actual file for the entire definition):

object ProjectBuild extends Build {

  val main = Project(
    "sbt-example-qa",
    new java.io.File("."),
    settings = Defaults.defaultSettings ++ ProjectSettings.all
  )
}

On the other hand, the Build.scala file generated by the 'play new' command has a different structure:

object ApplicationBuild extends Build {

  val appName         = "play-example-qa"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
    javaCore,
    javaJdbc,
    javaEbean
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here  
  )
}

Specifically, the Build.scala file created by 'play new' defines a play.Project rather than a Project as create by the giter8 template.

All my attempts to "Add my own project settings here" to get Checkstyle and PMD into the Play projecthave failed with syntax errors such as the following:

[info] Loading project definition from /Users/johnson/projecthosting/github/play-  example-qa/project
[error] /Users/johnson/projecthosting/github/play-example-qa/project/Build.scala:17:   overloaded method value settings with alternatives:
[error]   (ss: sbt.Project.Setting[_]*)sbt.Project <and>
[error]   => Seq[sbt.Project.Setting[_]]
[error]  cannot be applied to (settings: Seq[sbt.Project.Setting[_]])
[error]   val main = play.Project(appName, appVersion, appDependencies).settings(
[error]                                                                 ^
[error] one error found
[error] (compile:compile) Compilation failed

For your reference, here is the sample Play project I am trying to create that merges the giter8 template:

https://github.com/ics-software-engineering/play-example-qa

Can someone explain how to modify Build.scala in this project so that the Play console can accept the "checkstyle" and "pmd" commands in a manner similar to the giter8 template? Perhaps by forking the play-example-qa project and fixing Build.scala? I intend to make the working code available to the Play community for future reference. Thanks in advance.

1 Answer 1

5

I've created a GitHub repo that answers your question.

You can start with that project, or manually follow these steps to adapt my giter8 template to Play:

  1. First make a new Play project with play new foo, choosing 2 for Java.
  2. Put the template's pmd-ruleset.xml and checkstyle-config.xml in the Play project directory.
  3. Copy the object ProjectSettings from the template's project/build.scala into Play's project/Build.scala.
  4. Add the contents of the template's project/plugins.sbt to Play's project/plugins.sbt, remembering to leave a blank line before you paste.
  5. Last, change the Play project/build.scala to actually use ProjectSettings.all from the template:

    
    val main = play.Project(appName, appVersion, appDependencies).settings(
      ProjectSettings.all: _*
    )
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.