IntelliJ "Cannot infer Scala class path..." but Gradle testCompile is correct?

Viewed 6057

I've got a Spring Boot project building through Gradle that recently saw the addition of some Gatling tests. The Gatlings stuff, which needs Scala support, is all down in src/test/scala. The build.gradle file got a new testCompile dependency to support it and, from a gradle perspective, all is well...

build.gradle

apply plugin: 'scala'
...
dependencies {
  ...
  testCompile "org.scala-lang:scala-library:2.11.1"
  testCompile "io.gatling.highcharts:gatling-charts-highcharts:2.2.5"
  ...
}

The gradle docs suggest that testCompile is all we need here: https://docs.gradle.org/current/userguide/scala_plugin.html

IntelliJ is unhappy with this configuration insisting

Warning:<i><b>root project 'tenderfoot': Unable to build Scala project configuration</b>
Details: org.gradle.api.GradleException: Cannot infer Scala class path because no Scala library Jar was found. Does root project 'tenderfoot' declare dependency to scala-library? Searched classpath: configuration ':compileClasspath'.</i>

If I lift the dependency up from testCompile to compile, the intellij warning goes away, but now my spring boot uber jar thing is unnecessarily bloated.

What's the way out? How do I get IntelliJ to stop Warning on this?

Is this actually an IntelliJ bug?

1 Answers

I ran into this problem also (having to set the dependency manually from IntelliJ).

I "fixed" it by setting the dependency as compileOnly as opposed to compile, this scope does not include the JAR in the final distribution.

The code I use is (please note that my dependency includes Scala as a transitive dependency):

    compileOnly("io.gatling.highcharts:gatling-charts-highcharts:$gatlingVersion")
Related