kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
173 stars 57 forks source link

'Go To Type ' not working for srcDirs with include #421

Open markokaestner opened 5 years ago

markokaestner commented 5 years ago

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

kelemen commented 5 years ago

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

markokaestner commented 5 years ago

You can find a sample project here.

kelemen commented 5 years ago

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 commented 5 years ago

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

markokaestner commented 5 years ago

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

kelemen commented 5 years ago

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)?

markokaestner commented 5 years ago

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.

kelemen commented 5 years ago

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

markokaestner commented 5 years ago

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.

kelemen commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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).

markokaestner commented 5 years ago

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.

kelemen commented 5 years ago

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).

markokaestner commented 5 years ago

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.