I am trying to use scala test with gradle. Below is a snapshot of what my build.gradle looks like. My IntelliJ scala SDKs also point to the very latest. I have been working on this for the past two days, but have not been successful. I tried changing libraries or SourceSets, but nothing changed the error messages. If I do not use SourceSets, it throws errors in all class files, regardless of Java or Scala. Below is what my folder structure looks like:
src -main -java -scala -test -groovy -scala //start of my gradle file. apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'wrapper' apply plugin: 'scala' sourceCompatibility = 1.8 version = '1' repositories { mavenCentral() mavenLocal() jcenter() } dependencies { //json marshalling compile 'org.json4s:json4s-jackson_2.11:3.2.11' compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2' compile 'com.google.code.gson:gson:2.3.1' compile 'com.googlecode.json-simple:json-simple:1.1' //scala compile "org.scala-lang:scala-library:2.11.7" //scala testCompile "org.scala-lang:scala-library:2.11.7" testCompile(group: 'org.scalatest', name: 'scalatest_2.11', version: '2.2.4') } sourceSets { main { scala { srcDirs = ['src/main/scala','src/main/java'] } } test { scala { srcDirs = ['src/test/scala'] } } } sourceSets { main { output.resourcesDir = "build/classes/main" } } //not sure whether an Ant task helps? I grabbed from after a google search. test << { ant.taskdef( name: 'scalatest', classname: 'org.scalatest.tools.ScalaTestAntTask', classpath: classpath.asPath ) println("test classes dir" + testClassesDir) ant.scalatest( runpath: testClassesDir, haltonfailure: 'true', fork: 'false') { reporter(type: 'stderr') reporter(type: 'junitxml', directory: 'build/reports/junitxml') } } Following is the command I use to run the tests: ./gradlew clean test and the error log reports: :compileTestScala error: missing or invalid dependency detected while loading class file 'package.class'. Could not access type ScalaObject in package scala, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'package.class' was compiled against an incompatible version of scala. one error found Any pointers would be helpful.
source share