How do I configure a custom source set containing Scala sources?


I have a custom directory layout that contains a number of extra ‘test’ directories in my scala project.

I would like to define an extra scala sourceSet for these test directories, so I added the following to my build:

sourceSets {
    testIntegration {
        scala {
            srcDir 'src/test-integration/scala'

but when I run

$ gradle compileTestIngerationScala

I get

$ gradle compileTestIntegrationScala
:compileTestIntegrationJava UP-TO-DATE
[ant:scalac] object scala not found.

I think I must have misunderstood the scala plugin documentation. How do I define a custom scala (test) source set?

/Raymond Barlow

Each source set has its own ‘compile’ and ‘runtime’ configurations. Hence you need to put scala-library on the integrationTestCompile class path:

dependencies {
  integrationTestCompile 'org.scala-lang:scala-library:2.8.1'

Hi Peter,

I tried this, and it didn’t seem to work. I added the above, and now get:

$ gradle -q clean compileScala
  FAILURE: Build failed with an exception.
  * Where:
Build file '/Users/rbarlow/Development/projects/project/build.gradle' line: 51
  * What went wrong:
A problem occurred evaluating root project 'project'.
Cause: Could not find method integrationTestCompile() for arguments [org.scala-lang:scala-library:2.9.1] on root project 'project'.

Never mind, worked out it was just a typo (should’ve been testIntegrationCompile, not integrationTestCompile).

Cheers! /Raymond