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


(Raymond Barlow) #1

Hi,

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
:compileTestIntegrationScala
[ant:scalac] scala.tools.nsc.MissingRequirementError: object scala not found.
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:655)
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.getModule(Definitions.scala:605)
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackage(Definitions.scala:145)
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackageClass(Definitions.scala:146)
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.AnyClass(Definitions.scala:176)
[ant:scalac]
at scala.tools.nsc.symtab.Definitions$definitions$.init(Definitions.scala:814)
[ant:scalac]
at scala.tools.nsc.Global$Run.<init>(Global.scala:697)
[ant:scalac]
at scala.tools.ant.Scalac.executeInternal(Scalac.scala:629)
(etc)

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

/Raymond Barlow


(Peter Niederwieser) #2

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'
}

(Raymond Barlow) #3

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'.

(Raymond Barlow) #4

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

Cheers! /Raymond