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.
170 stars 57 forks source link

error on import statements of test classes using module-info #417

Open ghost opened 5 years ago

ghost commented 5 years ago

Could not setup simple java gradle project with module-info.java and tests without error using java 11. Netbeans gradle shows me error on import statements of test-classes using java jigsaw module-info.

Simple gradle Java project with:

gradleJava/src/main/java/module-info.java:

module gradleJava {
    requires java.desktop;
}

gradleJava/src/test/java/PropertyChangeListenerTests.java:

import java.beans.PropertyChangeListener;

public class PropertyChangeListenerTests {

    @Test
    public void propertyChangeListenerTest() {
        PropertyChangeListener listener;
    }
}

Netbeans shows the line "import java.beans.PropertyChangeListener;" as error: "package java.beans" does not exist.

Expect that netbeans-grade plugin uses module-info.java of src/main for src/test and does not show the error on the import statements of the test. I want to use different locations src/main for source code and src/test for unit tests.

I tried it in IntelliJ and there it works as expected.

Screenshot of error in netbeans: error on import statements

Simple sample project for opening in netbeans to show the error: gradleJava.zip

kelemen commented 5 years ago

Can you try using somethine else than the default package?

ghost commented 5 years ago

The same error on tests exists also when I use a package. I have stripped down the error in the attached gradleJava.zip to a minimum, for easy reproducing and fix.

error module-info and test

Our main goal is to contribute to openjdk-jfx, but there I have the same problem in the tests.

error openjdk-jfx

kelemen commented 5 years ago

Thanks for the report and the sample project, I will have a look next week (or maybe sunday), as I'm on holiday at the moment.

ghost commented 5 years ago

Have a nice holiday! If I can be of assistance, please do not hesitate to contact me. For developing with java jigsaw module system, it is essential to have this bug fixed.

kelemen commented 5 years ago

I have made some adjustment to better mimic what the Maven integration does. However, I'm a little puzzled on what actually NB is doing to use the module-info.java from the main source set. However, the recently pushed changes seems to fix the issue for me.

Can you try building the master branch and see if it works for you?

ghost commented 5 years ago

I will try and write my feedback here :-)

ghost commented 5 years ago

I build the master branch with your changes and verified the behavior.

Sadly it did not change anything for me. In the class "PropertyChangeListenerTests" the "import java.beans" are highlighted again as error with the same tooltip "package java.beans does not exists".

If we make an appointment, i can share you my screen over skype, so that you can verify what I have done.

Have you tried opening the attached project in "gradleJava.zip" with your changes?

kelemen commented 5 years ago

I have checked this with your attached project. To be honest I closed the file and then the project, restarted NB and opened the project again (that said, this hints to a very unreliable behaviour). No need to share your screen, I believe you and you shouldn't really be able to do the wrong thing. It seems I will have to check some other things.

That said, the current development version of NB has a completely different Gradle integration packaged. I recommend you building NB from the sources (https://github.com/apache/incubator-netbeans), it is pretty easy to build (though takes a while), and see if that works for you first.

ghost commented 5 years ago

I have cloned and build incubator-netbeans like you recommended. Good news, the "import java.beans." in PropertyChangeListenerTests is now correctly validated as expected. If I remove the associated "requires java.desktop;" line from module-info.java, the validation shows an error in PropertyChangeListenerTest as expected, if i add the "requires"-statement, it show no validation error in this line as expected.

Bad news, now the import-statement of "import org.junit.Test;" is now shown as error, with the message "package org.junit is not visible ...", but maybe this behavior is correct and I have to do some more configuration in netbeans? Any hint or tips for me?

bildschirmfoto 2019-02-06 um 16 55 18

ghost commented 5 years ago

As you can see on the following screen-shot in the build incubator-netbeans the test passed successfully. So I can run it. Therefore I do not understand why netbeans is showing me the error "package org.junit is not visible.."?

bildschirmfoto 2019-02-06 um 17 22 17

kelemen commented 5 years ago

I had a brief look at the source code, and it seems that it misses an implementation of CompilerOptionsQueryImplementation. That said, I wonder if implementing that will make that plugin has the same issue as this one.

Anyway, you should report issues of that plugin here: https://issues.apache.org/jira/projects/NETBEANS/issues

ghost commented 5 years ago

I have found an already created issue for this error: https://issues.apache.org/jira/browse/NETBEANS-2004 and I append what I already wrote here and copied also the link to here.

Maybe if we can get in touch with a developer from netbeans knowing the relevant module/code, the solution/knowledge found out can be relevant or helpfull for fixing both issues, your plugin and the incubator-netbeans gradle integration.

kelemen commented 5 years ago

I have already talked about this with an NB developer but it seems I did not quite understood what is to do properly. Anyway, I will try harder to analize the sources of NB a little harder but I'll probably only have time on the weekend.

kelemen commented 5 years ago

I went through some NB and nb-javac sources on the weekend but it seems a little odd to me because - though I probably missed something - the only way I saw to tell NB to use the main's module-info.java in test is to have them on the same source path but I remember that doing so causes other weird issues (not to mention that the Maven integration does not do that). I will need more time for this (something I have little of at the moment).

ghost commented 5 years ago

Thanks for you patience for further investigation. Hope that this issue will also be fixed in the incubator-netbeans. Can I do something to support them?