How do I make scala and groovy plugins play well together?

I’m working on a scalatest project over here: https://github.com/jasonnerothin/gs-scalatest/blob/3bfb9661c94b15c6c9b3511485e1f57091a12882/build.gradle .

But then I wanted to add groovy support…

Really all I want to do is have both the scala and groovy plugins dump their compile outputs into the build directories and then run their tests (at this point). Thoughts on how to get this to work?

I don’t mind writing my own plugin, probably by extending either scala or groovy…

What problems did you encounter with the straightforward ‘apply plugin: “scala”; apply plugin: “groovy”’?

scala tests run, but groovy tests seem not to. Wonder if there’s an update check mismatch or something…

Here’s the relevant snippet from ‘gradle test -i’:

elected primary task ‘test’ Tasks to be executed: [task ‘:compileJava’, task ‘:compileGroovy’, task ‘:compileScala’, task ‘:processResources’, task ‘:classes’, task ‘:compileTestJava’, task ‘:compileTestGroovy’, task ‘:compileTestScala’, task ‘:processTestResources’, task ‘:testClasses’, task ‘:test’] :compileJava (Thread[main,5,main]) started. :compileJava Skipping task ‘:compileJava’ as it has no source files. :compileJava UP-TO-DATE :compileJava (Thread[main,5,main]) completed. Took 0.023 secs. :compileGroovy (Thread[main,5,main]) started. :compileGroovy Skipping task ‘:compileGroovy’ as it has no source files. :compileGroovy UP-TO-DATE :compileGroovy (Thread[main,5,main]) completed. Took 0.001 secs. :compileScala (Thread[main,5,main]) started. :compileScala Skipping task ‘:compileScala’ as it is up-to-date (took 0.512 secs). :compileScala UP-TO-DATE :compileScala (Thread[main,5,main]) completed. Took 0.527 secs. :processResources (Thread[main,5,main]) started. :processResources Skipping task ‘:processResources’ as it has no source files. :processResources UP-TO-DATE :processResources (Thread[main,5,main]) completed. Took 0.005 secs. :classes (Thread[main,5,main]) started. :classes Skipping task ‘:classes’ as it has no actions. :classes UP-TO-DATE :classes (Thread[main,5,main]) completed. Took 0.001 secs. :compileTestJava (Thread[main,5,main]) started. :compileTestJava Skipping task ‘:compileTestJava’ as it has no source files. :compileTestJava UP-TO-DATE :compileTestJava (Thread[main,5,main]) completed. Took 0.005 secs. :compileTestGroovy (Thread[main,5,main]) started. :compileTestGroovy Skipping task ‘:compileTestGroovy’ as it is up-to-date (took 0.101 secs). :compileTestGroovy UP-TO-DATE :compileTestGroovy (Thread[main,5,main]) completed. Took 0.11 secs. :compileTestScala (Thread[main,5,main]) started. :compileTestScala Skipping task ‘:compileTestScala’ as it is up-to-date (took 0.036 secs). :compileTestScala UP-TO-DATE :compileTestScala (Thread[main,5,main]) completed. Took 0.042 secs. :processTestResources (Thread[main,5,main]) started. :processTestResources Skipping task ‘:processTestResources’ as it is up-to-date (took 0.007 secs). :processTestResources UP-TO-DATE :processTestResources (Thread[main,5,main]) completed. Took 0.017 secs. :testClasses (Thread[main,5,main]) started. :testClasses Skipping task ‘:testClasses’ as it has no actions. :testClasses UP-TO-DATE :testClasses (Thread[main,5,main]) completed. Took 0.001 secs. :test (Thread[main,5,main]) started. :test Executing task ‘:test’ (up-to-date check took 0.001 secs) due to:

Task has not declared any outputs. [ant:scalatest] Discovery starting. [ant:scalatest] Discovery completed in 134 milliseconds. [ant:scalatest] Run starting. Expected test count is: 4

For purposes of discussion, I’m now working off of this branch: https://github.com/jasonnerothin/gs-scalatest/tree/example

Maybe I’m violating some sort of naming convention in the groovy test compiler for this class:

https://github.com/jasonnerothin/gs-scalatest/blob/example/src/test/groovy/GsPlatformTest.groovy

:compileGroovy

Skipping task ‘:compileGroovy’ as it has no source files.

:compileGroovy UP-TO-DATE

Judging from the log output, your build somehow overwrites the ‘test’ task to call ‘ant:scalatest’. This probably won’t work for executing Groovy tests (supposedly) written in JUnit. Perhaps you can instead run the Scala tests using JUnit (and without altering the ‘test’ task). From what I remember, ScalaTest provides a JUnit runner for this. Alternatively, you can run the Groovy tests with the (unaltered) ‘test’ task, and the Scala tests with a separate ‘scalatest’ task that calls ‘ant:scalatest’. The latter should probably be a custom task which isn’t based on the ‘Test’ task type.

Sounds about right. I can throw the ‘overwrite’ flag to false here (https://github.com/jasonnerothin/gs-scalatest/blob/472870c35e65b29fb627bba45afc3b46e8f41fcb/build.gradle#L74), but then ‘gradle test -d’ yields:

5:38:19.973 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.InvalidUserDataException: Cannot add task ‘:test’ as a task with that name already exists.

Unless the scalatest config can be re-worked? I feel like my best option is … plugin engineering?

You should get rid of your redeclaration of the ‘test’ task, and instead add a ‘scalatest’ task for executing the Scala tests. The Groovy tests will be executed by the ‘test’ task introduced (indirectly) by the Groovy plugin.

Thanks. This did the trick nicely.