NetBeans doesn't recognize that dependency is a local project - how to fix? - maven

I have two pairs of projects that I develop in NetBeans, both of which have a GUI project, and a library project, where the GUI project depends on the library one. In one of them, NetBeans recognizes that the dependency is local, and indicates as such with an Ma symbol, as seen below, with the dependency project in green:
This provides some nice functionality, most notably that the "Navigate to" (ctrl+click) functionality from the GUI project takes me to the source code in the library project. I also don't have to manually rebuild the library project for the GUI project to pick up any changes.
However, for the other pair of projects, NetBeans will pick up that the dependency is in my local Maven repo, but does not recognize that the source code is a Maven project that it also has open:
I've tried looking through all the right-click menu options, removing and re-adding the dependency from the NetBeans GUI, comparing the pom.xml, comparing nb-actions.xml, and nb-configuration.xml, but cannot find any explanation of why one library is recognized as local, but the other is not. The only information I've found online is at http://wiki.netbeans.org/MavenBestPractices, where it notes:
"Hint: If you open a project that other projects depend on, the icon in other projects changes to a "maven project" icon to denote that the IDE knows about link between the projects. However such a link is only established when the groupId, artifactId and version all match in the dependency and project declaration. Frequently occurring problem is that you change an API signature in your library project, but the application is not picking up. Often it's caused by the fact that the application is using an older version of the library artifact. The artifact icon can help you track down these problems."
However, I've verified that the pom.xml of the GUI project depends on the version being built in the library project, and even made the versions identical between the GUI project and library, and the "maven project" icon still doesn't show up.
Does anyone know how to debug this issue, or if there's a magic setting somewhere that I'm missing for how to make this link work? I've been trying with both NetBeans 8.2 and 8.1, and am compiling with Java 8 for both the successful pair of projects, and the unsuccessful ones.

Revisiting the project a couple years later, I finally figured out a way to get the dependency to connect locally.
Change the artifact ID of the dependency, and update the dependent pom to match the new name.
This is admittedly bypassing the root issue rather than addressing it, but given the inability to pinpoint the root cause, seems the best option at this time.

Related

Modules, Gradle Subprojects, and IntelliJ Woes?

I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ.
My project structure is as follows:
Root
- settings.gradle
- core
- build.gradle
- desktop
- build.gradle
- src/main/java/module-info.java
The desktop build.gradle file as a requirement on core as:
dependencies {
implementation project(":core")
}
There is no reference to the "core" project in the module-info.java files.
In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.
My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.
Would appreciate any insight.
P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?
I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.
There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:
In the Gradle tool window, click the top-left button Refresh all Gradle projects.
Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
Click the invalidate caches/restart in the main menu.
You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.
Hope these steps could help you.

Why refresh of Maven repository is not enough for IntelliJ?

I had a NoClassDefFoundError problem with some test, launched from IntelliJ. In order to repair the situation, I had to make several changes in many poms of the project - adding new packages and excluding some old ones for to escape the overlapping of them. Also, I reapired the situation with different versions. But the situation did not improve. Again, some package, declared in pom, was not found where it should be.
I refreshed the maven repository by
mvn -e clean install -U
, as is advised in https://stackoverflow.com/a/9697970/715269 - so old and upvoted answer, that it surely looks as Santa.
The problem remained unchanged.
I output the maven map. It was correct and it contained all needed.
I looked at the list of the External Libraries of the project. It was the old uncorrected list of overlapping jars with same names and different versions, and without good packages I added just now, and well seen in maven tree output!
Already hapless,
I reimported packages in IntelliJ
by:
Ctrl+Shift+A, Reimport All Maven Projects.
Ho! The list of libraries got repaired. And the problem, mentioned in subj, disappeared.
The question is: How it could happen, that the same project has that very pom for everything, but gets packages differently being launched in maven and in IntelliJ?
I know about that feature "delegate IDE build to Maven". And I keep it turned off. But I am NOT talking about the different SW for building. Whether they are different or not, they should be up to the actual pom's. And whereas maven, if turned off from the automatic building won't know about changes in poms, IntelliJ KNOWS about them. It could have jars up to pom, or up to maven - it has sense, but it simply has some old rubbish. Was there some deep thought under that construction?
Every time you manually change the pom.xml file, including the dependencies you need to load these changes into IDE. IDE does it on Reload from Maven action. See also Import Maven dependencies.
Intellij doesn't use maven to bulid and run a project except you are delegating build and run action to maven:
Since, IDEA doen't really use maven to run and build, it uses the pom.xml to import the project structure and "tries" to build the project the same way was maven does.
Actually, there are quite a few differences between these to build processes.
Generating sources or filtering resources (don't know if this is still an issue) aren't done during building the project with Intellij IDEA.
In case you are using code generation you have to build the project via maven first and then - when all the resouces are filtered and additional sources are generated - you are able to run, debug aso. the project with Inellij IDEA.
That's an important thing to be aware of and that's the reason why maven and IntelliJ IDEA project structures might get out of sync.
You can enable the "Reload project after changes in build scripts" feature and select the Any changes checkbox to keep your project structure updated:
Why should you disable this feature anyway
If you are working on a build file (gradle or maven is not important) reloading the structure on any change can be very anoying. It's cpu intense, dependcies are fetched aso.
Therefore, I prefer to reload project structure only in case of an external change. This happens when pulling an updated version of the build file for example.

Library development/debug with Maven

I am in the processing of integrating Maven into my my projects. While maven has plenty of pros i'm finding it difficult to figure out how to maintain my current development process, which is as follows:
For creating SDKs I will create a sample app, which will depend on and directly reference the SDK source code, all from within the same code project. This means that I can make easily change/debug the SDK code with one click run/debugging.
I fear this won't really be possible with Maven. Can I create some type of Hybrid approach, where I continue my normal development approach and then push builds to Maven when it is appropriate.
Update - For Clarity
My problem is that when everything is done through maven, the dependencies are built and published to Maven. Then, the dependent project pulls down compiled references and uses them. My issues is that I don't want to go through this whole process every time I make a small change to a dependency.Thanks.
You should try creating parent level pom.xml with two modules - your library and simple app to test it. In simple app's pom.xml provide a dependency on library module.
Then open in your IDE parent pom as maven project. This should be sufficient for normal debug.
Other possible approach - install you library artifact into maven repo with sources. In this case you will be able to debug it, but test app still have to load use jars from repo.

Intellij Debugging picking up old version project files

I am debugging code in Intellij. I use maven to build the project and there are various versions of the project sitting in the local .m2 repository. Intellij keeps on picking the old version of the code from the previous snapshot of the project when I start debugging. How do I make IntelliJ debug the latest code from the local repository?
You can tell Intellij 2016 to ask you each time which source code to step through.
File->Settings->Debugger
Show alternative source switcher
Try removing .jar and .war files that contain your code from your ~/.m2/repository/
For me the issue is that I built something and it is now registered in Maven under what Maven considers a newer version, but isn't what I was currently working on. I compiled, say, version "2.1" to debug something and then went back to working on "sand-box-idea-SNAPSHOT". I keep thinking why isn't Intellij picking up my latest sand box change but it's because it's deferring to the Maven version 2.1 which Maven assumes is better than 'sand-box-SNAPSHOT'.
It may be that you have some plug-ins interfering with IntelliJ's build process. I know that the Google Protocol Buffers Plugin can cause my Intellij to be unable to detect dirty classes that need to be re-compiled.
I've met similar behavior, maybe it can help you :-)
I developed app (using maven) and during the time I change output packaging from jar to war. Maven repository than contained both versions, jar and war, because maven does not remove old jar when you change it. As project pointed to mvn repository, it still used old reference to jar but new version within war was updated.
I was really upset as maven compilation and tests worked fine but Idea used me old version. I've had rebuild idea project and it worked later fine.
I have seen this very recently after upgrading from IDEA 13 to IDEA 14. It seems like launching configurations created in IDEA 13 are no longer automatically triggering a mvn package prior to launch.
In order to fix this I manually added a mvn goal in the "Before Launch" dialog.

intellij idea. what library uses project?

I have Android Maven project which works with Netbeans and Eclipse and compiles in command line itself, but i have some problems with Intellij Idea. After importing the project the IDE complains about non-existing method of imports:
import org.w3c.dom.Node;
cannot find symbol
symbol : method getTextContent()
The method getTextContent() added in java version 1.5. I do use 1.7 Oracles JDK. Build target in pom.xml points to 1.5
Similar post about problem in Eclipse mentioned here says:
There are many jars packaged with xml-apis and they sometimes contain the same library routines, but at different versions.
I have searched how to lookup which version of library is used with IDE and how to priorities the right libraries.
Do someone have the answer?
In intellij go to module settings (right click module and its in the context menu).
Select project, you can choose and/or add a project SDK here, If you are using 1.7 it will probably be that version.
when you make/compile your project its probably running against the version above.
You can run maven targets (in my version there is a tab on the right) you should be able to do this if you right click on the pom file, this should compile.
In conclusion
use the same java version on your pom and in your project
try to move Android SDK module up. in "Project structure" -> "Modules" -> "Dependencies". And make sure You do not have the old maven module xml-apis there.

Resources