1

In multiple project, IDEA can't find the all usages of the common project method and just found one of them which uses it. How to find usage across projects?

The version:

IntelliJ IDEA Community Edition 2022.2.3

gradle-4.1

The project:

projct folder

We can see the usage shows just the pj-serviceA project, but pj-serviceB is also using the pj-common method.

code:

pj-common:

package com.pj.common;

public class StringUtil {
    public static void print(String string) {
        System.out.println(string);
    }
}

pj-serviceA:

package com.pj.serviceA;

import com.pj.common.StringUtil;

public class Main {
    public static void main(String[] args) {
        StringUtil.print("A");
    }
}

pj-serviceB:

package com.pj.serviceB;

import com.pj.common.StringUtil;

public class Main {
    public static void main(String[] args) {
        StringUtil.print("B");
    }
}

the pj-serviceA and pj-serviceB all can run.

The problem:

only found one project

I want to find all the usages.

I invalidate all the caches, but can't solve it.

The project structure:

enter image description here enter image description here enter image description here enter image description here enter image description here

The running result:

enter image description here enter image description here

If it's not clear yet, I'll put the code on GitHub on the weekend and post the link.

Github: https://github.com/xiaotanwo/pj

invzbl3
  • 5,872
  • 9
  • 36
  • 76
xiaotan
  • 31
  • 3
  • The only reason that comes to mind is possibly a version difference : common is at version 2, service A uses version 2 of common but B uses version 1. Otherwise, without the project, it's hard to tell. – Bastien Aracil Mar 11 '23 at 17:09
  • Common version is same, the project is new for this problem. Both serviceA and serviceB, the build.gradle are the following dependencies { compile project(":pj-common") } – xiaotan Mar 13 '23 at 07:04
  • It's hard to say what the problem is without a project. Maybe you could use the IDE main menu `Help | Contact Support` to contact the IDEA support team with a sample project attached for checking. Normally, you should create a multi-module Gradle project with a parent module and include the common, serviceA, serviceB modules in it and let the serviceA and serviceB depend on the common module so the Find Usage would work. – LJ replica Mar 14 '23 at 03:42
  • Could you show, please, the whole structure of the project with the usage, e.g. [#1](https://stackoverflow.com/q/347551/8370915) or [#2](https://stackoverflow.com/a/61565622/8370915) (tree) with content inside each of class accordingly (instead of screen)? It'd would be more informative to reproduce your issue. – invzbl3 Mar 21 '23 at 02:10
  • 1
    I add more details. If it's not clear yet, I'll put the code on GitHub on the weekend and post the link. – xiaotan Mar 23 '23 at 06:59

1 Answers1

0

I've reproduced this specific bug using Java 8 & Gradle 4.1/7.1 & Windows 10.

Used & tested Intellij IDEA versions:

Intellij IDEA version 2023.1 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2022.3.3 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2022.2.5 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2022.1.4 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2021.3.3 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2021.2.4 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2021.1.3 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2020.3.4 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2020.2.4 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2020.1.4 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2019.3.5 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2019.2.4 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2019.1.4 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2018.3.6 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2018.2.8 Gradle 7.1 / Gradle 4.1 : (displays only one of the presented methods)

Intellij IDEA version 2018.1.8 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2017.3.7 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2017.2.7 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2017.1.6 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2016.3.8 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

Intellij IDEA version 2016.2.5 Gradle 7.1 / Gradle 4.1 : (doesn't display matches at all)

Intellij IDEA version 2016.1.4 Gradle 7.1 / Gradle 4.1 : (does not display matches at all)

As a possible workaround of it, you can use the combination Ctrl + Shift + F:

enter image description here

And the result will be displaying all usages, as you need per requirements. By typing, for instance, either StringUtil.print or simply print. It depends on your needs, of course.

(For testing purposes I used Intellij IDEA version as 2022.3.3)

Additional & helpful information:

  • Invalidate Caches -> Clear file system cache and Local History didn't work for me.
  • Double Shift didn't work for me also.
invzbl3
  • 5,872
  • 9
  • 36
  • 76
  • 1
    Thank you for the answer. Double Shift is vaild, but it is just working in the static method. If the method is object(the variable name will be different in different code), and the and other class also has the same name method. The double Shift find usages is not good in these conditions. I find the solution for this problem, make the three project as a project, it is the gradle problem. You can see it in new fix on my github. https://github.com/xiaotanwo/pj – xiaotan May 30 '23 at 10:29