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.

0

Try to delete .idea directory and reimport the project from pom.xml.

0

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?

0

There could be some error when the project was imported, see http://stackoverflow.com/a/42427510/104891.

0

Thanks, I'll check that when I can get onto the machine that had the problem.

0

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:

  1. Delete the module in the project view (not from the Maven Projects view)
  2. Delete the .iml file
  3. Un-ignore the module in Maven Settings -> Ignored Files
  4. Do a Maven Reimport

It's not a perfect solution, but it's a little quicker than deleting the .idea directory and recreating it.

Thanks for your help.

0
Avatar
Permanently deleted user

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.

0

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:

<module version="4">
<component name="ExternalSystem" externalSystem="Maven" />

If I change this section to the following:

<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">

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.

0

Thanks for information! I'll add workaround to related issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-185676

0

请先登录再写评论。