netbeans-gradle-project icon indicating copy to clipboard operation
netbeans-gradle-project copied to clipboard

'Go To Type ' not working for srcDirs with include

Open markokaestner opened this issue 5 years ago • 15 comments

I have a multi-module project which has only one src directory for all subprojects. The srcDirs then use an include to select the correct packages:

subprojects {
    sourceSets {
        main {
            java {
                srcDirs = ["${rootDir}/src/main/java"]
                include 'some/common/prefix/' + project.name.replace('-', '/') + '/**'
            }
        }
    }
}

This works as far as all packages, that are not included, are empty in the project view. Java files in included packages are correctly shown in the project view.

If I try to open a class that I can clearly see in the project view via "Go To Type", the class is not found. This also affects imports of classes from the same subproject. The imports are highlighted with "package not found".

issue

markokaestner avatar Mar 26 '19 16:03 markokaestner

I have tried this and I'm not experiencing the same issue. Do you have a sample project to try this with?

kelemen avatar Mar 27 '19 22:03 kelemen

You can find a sample project here.

markokaestner avatar Mar 28 '19 08:03 markokaestner

I'm assuming this has something to do with the modules. Does it happen if you disable modules in the project properties? (Java Modules/Allow Modules)

kelemen avatar Mar 28 '19 23:03 kelemen

Since disabling modules is a bit of a hack, you might want to restart NB after that.

kelemen avatar Mar 28 '19 23:03 kelemen

I updated to the latest plugin version and disabled the java modules globally. But as the project is only JDK8, that had no effect. It's still not working.

I checked the logs and found these entries:

WARNING [org.netbeans.modules.project.ui.OpenProjectList]: Project dir with file:/SOME_PATH/nb-gradle-test/a/ not found!
WARNING [org.netbeans.modules.localhistory]: source group a returned null root folder
...
WARNING [org.netbeans.modules.java.source.indexing.JavaIndex]: Ignoring root with no ClassPath: /home/mk/Projekte/nb-gradle-test/src/main/java

The rest of the logs looks unsuspicious

markokaestner avatar Mar 29 '19 06:03 markokaestner

Does "/SOME_PATH/nb-gradle-test/a/" actually exist? Can you still try disabling modules to check if there is really nothing because of that (to check if the module support does not create a problem in your case for some weird reason)?

kelemen avatar Mar 30 '19 00:03 kelemen

The path "/SOME_PATH/nb-gradle-test/a/" does exist. It's an empty folder which exists for each of the submodules. Java 9 modules have been disabled in global settings and NB was restarted. The issue still persists.

markokaestner avatar Apr 01 '19 05:04 markokaestner

I'm not sure because it works for me fine. Have you tried removing the NB cache?

kelemen avatar Apr 02 '19 20:04 kelemen

Yes I tried all of that. I removed the nb cache as well as the .gradle folder and the .nb-gradle settings file. I also tried it with NB 8.2 - 10.0.

Can you please try to add a new class to one of the subprojects. That should break the demo project for sure.

markokaestner avatar Apr 03 '19 05:04 markokaestner

Hmmm, now I can reproduce it in NB 8.2 (without adding new classes) but not in 10. I'll try to find out what might be happening.

kelemen avatar Apr 03 '19 20:04 kelemen

The NB repo says its temporary unavailable, so I can't build the plugin for 8.2 at the moment. I'll check it tomorrow.

kelemen avatar Apr 03 '19 20:04 kelemen

I think I know what the issue is (not 100% because I didn't track down the issue to what actually happening in NB). That is, this is the problem: Your project has the same source root (regardless that it is distinctly filtered) for multiple projects and this confuses NB, because NB requires ownership for files and dirs, and now multiple projects provides source roots with the same root. So, the ownership is ambigous, and can (and does) confuse NB completely. I don't think this is fixable, because this is such an integral part of the NB infrastructure. So, I recommend you not share source root between projects if possible but if you need it shared then have a 3rd project which includes both (this I have done with buildSrc, and should work).

kelemen avatar Apr 04 '19 20:04 kelemen

That solves the issue although I don't like to have IDE specific settings in the gradle files especially when working in a team where different iDEs are in use. But that's at least better than being forced to switch to eclipse. Thanks for your help.

markokaestner avatar Apr 12 '19 07:04 markokaestner

You can always use an init script and pass an afterEvaluate there (you can check for some properties, if you are in the right build, or check for the presence of an excluded build script, and apply that).

kelemen avatar Apr 12 '19 09:04 kelemen

I was looking into that but did not find a reliable way to add an addition subproject from the init.gradle without any modifications to the project gradle files. Any hints would be appreciated.

markokaestner avatar Apr 12 '19 11:04 markokaestner