Bob Kuhar
Bob Kuhar

Reputation: 11100

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

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?

Upvotes: 4

Views: 9023

Answers (2)

Saisumanth Gopisetty
Saisumanth Gopisetty

Reputation: 946

You need to Add Scala SDK and set it to the Project specifically. Also, I had to invalidate cache and rebuild the project.

Add Scala SDK to the Project:

1.  Go to File > Project Structure (or press Ctrl+Alt+Shift+S).
2.  In the Project Structure window, select Project on the left panel.
3.  Under Project SDK, ensure that a valid JDK is selected.
4.  Next, select Global Libraries (or Modules if working with a multi-module project).
5.  Click the + icon to add a new global library, and choose Scala SDK.
6.  IntelliJ should automatically download and configure the Scala SDK. If not, you may need to specify the path manually if you have Scala installed locally.

Set Scala SDK for the Module:

1.  In the Project Structure window, go to Modules on the left panel.
2.  Select your module from the list.
3.  Go to the Dependencies tab.
4.  Click + and select Library > Scala SDK if it’s not already added.

Upvotes: 0

jaguililla
jaguililla

Reputation: 2076

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")

Upvotes: 1

Related Questions