Maven runtime dependency not available when compiling test
We have a Maven project which for most of the team works fine in IntelliJ IDEA 2017.3. However, one developer is having an issue very similar to this bug report from 2010.
The Maven module has a runtime dependency, and one of the unit tests creates an instance of a class from this dependency. Running "mvn install" from the command line works. The editor shows no errors. However, when compiling in IDEA (right-click, build module), the compiler fails to find the package that the class is in.
Running "mvn test-compile -X" on the module shows that the runtime dependency is included in the classpath when compiling the tests.
We have tried clearing the associated dependency from the local maven repository, and when we "Reimport Maven Projects", the dependency is re-downloaded, but the issue persists.
This issue has affected me in the past, and I ended up reinstalling and reconfiguring.
The version of IDEA being used on the project is 2017.3.2.
Regards, Rob.
Please sign in to leave a comment.
Try to delete .idea directory and reimport the project from pom.xml.
Thanks, that seemed to resolve the problem - we also deleted the .iml files, "just in case".
Still I'm trying to work out why the issue happened for just that developer, and not for everyone on the project. I will compare his and my .idea directories to see if there's anything obviously different, and report if that's the case. The only thing I can see could be some entries not being created in the "libraries" directory?
There could be some error when the project was imported, see http://stackoverflow.com/a/42427510/104891.
Thanks, I'll check that when I can get onto the machine that had the problem.
Hi. I haven't seen anything in the idea.log to suggest what the issue may have been, but I have found that the following sequence works to resolve the issue per module:
It's not a perfect solution, but it's a little quicker than deleting the .idea directory and recreating it.
Thanks for your help.
I have the same problem, i tried following ways to resolve the problem:
* deleting .idea directory
* reimporting maven project
* invalidating caches/restart
* reinstalling intellij idea
and nothing worked. Everything apart running tests works fine.
Please contact support using https://intellij-support.jetbrains.com/hc/requests/new and provide the sample project to reproduce, plus the logs (https://intellij-support.jetbrains.com/hc/articles/207241085).
Sorry for waking up this old thread, but I found a way to resolve this issue, and it looks like the problem is with how IntelliJ IDEA handles the fact that it's a Maven project in the .iml file.
Projects that fail to recognise runtime-scope dependencies during the test-compile phase have the following in their .iml file:
If I change this section to the following:
Removing the "ExternalSystem" component tag, then IntelliJ correctly recognises the runtime-scope dependency within the test-compile phase.
We get this on our project a lot (it's a very large project), and making this change has so far worked 100% of the time to resolve the issue. So much so that I wrote a script to make the change on all of our .iml files.
Regards, RobC.
Thanks for information! I'll add workaround to related issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-185676