We have a large multi-module Maven project. The usual working style is to check out a few modules you're interested in, and for the other modules they depend on, use snapshot JARs provided by Maven.
This mostly seems to work; when we need updated snapshot开发者_运维知识库s, we just force a reimport from the "Maven Projects" tab. However, the reimported snapshots never seem to get reindexed.
Steps to reproduce:
- In one project, check out / configure a module that depends on a Maven snapshot of some other module.
- In a separate project, make a change to that other module, e.g. adding a method, and deploy it to the Maven repository.
- In the first project, update the snapshot.
- In the first project, write some code that calls the new method.
Expected:
- No trouble calling the new method.
Actual:
- Method call is redlined with "Cannot resolve method" error. However:
- Code does compile (via the Build or context menu)
- Code does run, including code that calls the new method
Is there some way around this? It would be nice to get rid of the redline, have autocomplete etc. work, and in general be able to continue to use IDEA the way you're supposed to.
Possibly relevant: We have a mix of Eclipse and IDEA developers, and in order to work around some Eclipse/Maven integration bugs, we've set the snapshot updatePolicy to "never" in our pom.xml files. However, I would expect the IDEA setting (Snapshot update policy: Always update) to override this, unless I misunderstand what the setting does.
("Never" might seem counterintuitive, but I think it's correct for developers: update dependencies manually, just as you update source code from the VCS manually. For real builds, we have Hudson override the POM settings anyway. And more importantly, setting it to "never" stops Eclipse from rabid unnecessary total recompiles.)
Sometimes clicking 'synchronize' (the yellow arrows near the save button at the top left of the window) fixes this for me - I think it forces IDEA to look for any updated JAR files on the filesystem. Could be a bug in filesystem notification...
(In this case your maven project is pointing to all the right JARs, but IDEA hasn't re-indexed the new JAR file. So it's the filesystem index that's the problem, not the maven project setup)
I performed the following:
Open Preferences > Build, Execution, Deployment > Build Tools > Maven > Repositories
Select the appropriate repositories (Local) and click on Update.
This re-indexing and searching for a newly added class in the dependency jar worked and IntelliJ suggested the artifact and the relevant import.
Sorry I don't really have a true answer but I very much suspect that your problem comes from the updatePolicy being set to never. Could you clarify why you believe that to be necessary? I would not at all be surprised if the IDEA setting does not override this correctly. You could use the maven help plugin with the effective pom to see if it comes out right for IDEA.
Oh and your justification in () at the end sounds very dubious. I have not had these problems in Eclipse. Are you using the M2Eclipse plugin? I think "never" is NOT correct for developers. In fact I believe it should be always for developers .. which is the default behaviour.
精彩评论