Our team manages Java projects using Maven. We have a policy that all code on the master
branch of a repository should:
-SNAPSHOT
version (releases are created using the Maven Release plugin)-SNAPSHOT
s. This has an unfortunate consequence in IntelliJ IDEA (version 15, build 143.1821.5). Suppose Maven artifact A depends on some release version of Maven artifact B, say 1.2.3
. The current code for B
on master
, though, will be something like 1.2.4-SNAPSHOT
. If I load the source for both A
and B
in IDEA, go to a class in B
which is used in A
, and do a Find Usages
(Ctrl-click the class name or Alt-7
), no results are found. If, however, I navigate in the IDE to the decompiled class file for the 1.2.4
release and do Find Usages
, it finds the usages in A
.
I understand why this happens --- the -SNAPSHOT
version of the code really isn't being used by A
--- but this degree of pickiness makes Find Usages
nearly useless across Maven artifacts. However, I seem to remember at some point in the recent past IDEA's Find Usages
wasn't so picky. Unfortunately Googling hasn't turned up anyone else mentioning this problem or a mention of a change in IDEA behavior, so now we are thinking we just imagined the previous behavior.
So, does anyone know how to get IDEA to ignore version mismatches on Maven modules when doing Find Usages
? Was there some setting we had enabled before that we now can't find?
In the editor, select a symbol for which you want to see the usages. From the main menu, select Edit | Find Usages | Show Usages In Code Ctrl+Alt+F7 . The usages window shows the current scope and total count of usages. If you want to quickly switch to the default scope, press Ctrl+Alt+F7 .
In the POM, right-click anywhere in the editor to open the context menu and select Maven | Show Dependencies. Alternatively, press Ctrl+Alt+Shift+U or Ctrl+Alt+U . In the diagram window, IntelliJ IDEA displays the sub project and all its dependencies including the transitive ones.
Analyze dependencies From the main menu, select Code | Analyze Code | Dependencies. Alternatively, if you want to analyze a specific item, right-click it in the Project tool window and select Analyze | Analyze Dependencies. In the dialog that opens, specify the scope of files that you want to analyze.
If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local . m2 repository to see if it was downloaded correctly.
I think you're doing this incorrectly.
By definition, the MASTER branch should be a released version (no -SNAPSHOT).
You want to talk to your team and review your build and release processes.
Have a read about the git-flow branching model for some more information about branching strategies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With