Repository navigation
Description
Apache NetBeans version
Apache NetBeans latest daily build
What happened
Working on a modular java project which uses a non-modular project which does have an Automatic-Module-Name entry in its manifest, referenced by the module-info.java in the modular project, everything works fine, until I open the non-modular library as a project in NetBeans as well.
After that, the module name is no longer recognized, an all sources that use classes from the library are marked with errors.
Closing the library project and restarting does not solve the problem. Deleting index/ and the maven cache directories does not allow the IDE to forget the location of the library and begin working correctly again. I have no idea where this is getting cached (maybe it gets rediscovered via recent-projects in NbPreferences?), but short of deleting userdir and cache dirs, I have yet to find a way to recover.
(detailed steps with projects to check out to reproduce below).
What appears to be going on
- The IDE detects Automatic-Module-Name correctly in the case that the JAR file is used in the local Maven repo
- Once the project is open, since it is the same version referenced in the modular project's POM file, classes from the project are used directly - and there is no manifest to read
How you'd fix it:
- If one doesn't exist, there likely needs to be an SPI for Java project implementations to provide a
Manifestfor the project - or at least a module-name - synthesizing it on the fly if need-be - Maven support needs to provide an implementation that does something along the lines of
- Look for the
maven-jar-pluginin the project's pom or its parents' poms - If it exists, look for one of
- A manifest file being pointed in its configuration
- Look for a configuration -> archive -> manifestEntries configuration element, and if present, collect (at least) the entry for
Automatic-Module-Name
- Look for the
How to reproduce
Exact steps to clone two projects and reproduce the problem:
- Clone this project https://github.com/telenav/cactus and build it once - this project uses the java module system
- In the checkout dir, run
git checkout 1e61b40e34e5a09aa6f30d7c13c0df25d1ddecc5 - Build it once to make sure there are classes to scan -
mvn -Dmaven.test.skip=true install - Open some of the child projects in NetBeans - I'd recommend cactus-maven-model
- Browse around - there should be no error markers or problems
- Clone this project https://github.com/timboudreau/util which contains several libraries that are used from the previous one. This project does not use the java module system, but does provide an Automatic-Module-Name via its manifest
- In the checkout dir, run
git checkout 788f7fbed4c683874d234e61a494f16d7deb7bb5 - Build it once to make sure there are classes to scan -
mvn -Dmaven.test.skip=true install - Open the
functionproject from theutilcheckout - Error markers appear all over source files in the cactus project (you may need to do some editing or rebuild to make sure a reparse happens)
Did this work correctly in an earlier version?
No
Operating System
Mac OS X 21.4.0, Apple Silicon 10 Core MacBook Pro
JDK
Amazon Corretto 17
Apache NetBeans packaging
Own source build
Anything else
No response
Are you willing to submit a pull request?
Yes
Code of Conduct
Yes
Activity
timboudreau commentedon Jun 23, 2022
Ha - I may have located the way it is remembered - in my userdir, grepping for the string mastfrog I find
config/Preferences/org/netbeans/modules/maven/externalOwners.propertieswith entries likeneilcsmith-net commentedon Jun 24, 2022
I've had to work around this a few times. I'm not sure I wouldn't prefer an option to force use of the JAR over a manifest SPI though.
timboudreau commentedon Sep 1, 2022
Yeah, since I now have one big tree of non-modular libraries with
Automatic-Module-Name, and for work am working on another big tree of modular libraries that depend on the non-modular ones (which are public and still JDK-8 compatible and broader in scope), I now have two userdirs and two cache dirs, one for working on modular projects and one for working on non-modular ones.And if I ever forget and open one of the non-modular projects, I have to go edit a
.propertiesin my userdir. Not nice.