IDEA allows me to (incorrectly) import test classes from another module

Hi,

I have a multi-project gradle project (written in scala 2.11). Most projects depend on one or more of the other projects, for example:

sample-data-repository/build.gradle:

compile project(":sample-data-model")

Normally this would mean that all the classes in src/main/scala of sample-data-model are available on the classpath of sample-data-repository (both runtime and in tests).

However, IDEA's auto-completion and syntax checker seem to think that also the classes in src/test/scala of sample-data-model are available on the classpath of tests in sample-data-repository. For example, it will happily allow me to take some test class in sample-data-repository (e.g. PersonDmoRepositoryIT) and add a line that references a test class in sample-data-model (e.g. JsonModelSerializerIT). It autocompletes, there are no red lines, it compiles flawlessly, and IDEA will even run the test.

On the command line, however, gradle test will fail, complaining that:
... PersonDmoRepositoryIT.scala:16: error: not found: type JsonModelSerializerIT
  val x: JsonModelSerializerIT = new JsonModelSerializerIT


I would say that command line gradle is correct. The test classes of one module shouldn't be on the classpath of another module, not at runtime, not even during a unit test.

I find it hard to say why this is going wrong. Does it have something to do with configuration of the gradle plugin, scala compile server, ...?

I'm using IDEA 14.1.4 community edition, fresh out of the box (no configuration changes from the default, except a different font). I added the scala & gradle plugins after importing the project (as prompted by IDEA). The IDEA project was generated by gradle using gradle idea.

Any ideas?

Yours,

Jasper

P.S. The project I'm working on is on https://github.com/jasperavisser/octowight-example
1 comment
Comment actions Permalink

Hi Jasper,

it's known behaviour of IDEA with compile module dependencies.
Unfortunately, there is no support for cutomization of test classes visibility just for gradle projects.
See details at https://youtrack.jetbrains.com/issue/IDEA-126121

0

Please sign in to leave a comment.