Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ "Find Usages" and Maven artifacts

Our team manages Java projects using Maven. We have a policy that all code on the master branch of a repository should:

  1. itself have a -SNAPSHOT version (releases are created using the Maven Release plugin)
  2. have Maven dependencies only on releases and never on -SNAPSHOTs.

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?

like image 386
Ryan Gabbard Avatar asked Mar 11 '16 02:03

Ryan Gabbard


People also ask

How do I see all usages in IntelliJ?

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 .

How do I open Maven artifact search in IntelliJ?

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.

How do you read a dependency tree in IntelliJ?

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.

Why Maven dependencies are not showing in IntelliJ?

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.


1 Answers

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.

like image 175
vikingsteve Avatar answered Sep 23 '22 19:09

vikingsteve