Intellij not showing local library - maven

I'm trying to add a local library to a Maven project. Adding the corresponding dependency to the pom file works successfully, and so the project runs correctly. However, I'm trying to debug this library, for which I need to see the class files, which are not shown in the "External Libraries" option.
What could I do to fix this?

Related

Maven Build Scripts Found - IntelliJ - What are the build scripts, where are they cached?

So basically, as the title of the post states, I'm wondering what IntelliJ is referring to when it says that Maven build scripts were found? Are these scripts that Maven keeps cached or are they IntelliJ specific? If they are generated by Maven, where are they stored/ how can I view them if that is possible?
Thanks!
This notification is to inform you that you are working with IntelliJ IDEA project that is not linked to the external build system (Maven or Gradle).
When you open a project in IntelliJ IDEA that was not initially imported from Maven/Gradle and IDE detects pom.xml or build.gradle files in the project, it will display a notification so that you can properly import the project from the build script.
Build script in your specific case is a pom.xml file stored inside a project directory. It's recommended that you open Maven projects by importing the root pom.xml file.
When a project is not imported from the external build system, your source roots configuration may be incomplete and you may be missing the dependencies.

Gradle: Can't resolve a variable that has to be included in external dependency

This question follows this post: Gradle: Where are external dependencies stored?.
I want to use MongoDB driver for Java, so I added the following line:
compile 'org.mongodb:mongodb-driver:3.4.0'
to build.gradle file. After finishing the build successfully, I found the jar file of the dependency in ~/.gradle/caches/modules-2/files-2.1/org.mongodb.
I also added the path ~/.gradle to external libraries.
However, when I write the statement
import com.mongodb.MongoClient;
inside my project, I get an error:
"Can't resolve symbol 'mongodb'".
Do you know how to resolve this issue?
Now IJ searches in .gradle for classfiles. Of course mongodb is not found in there. As I said in the comment of the other issue, if you change the dependencies in your Gradle file and did not enable auto-import when you imported the Gradle project into IJ, its library configuration will not automatically update. Either tell IJ manually to refresh the library configuration from the Gradle file or activate auto-import so that it automatically sees when you change the Gradle file and automatically updates the library configuration.
Make sure you opened the project as Gradle project
When you add dependency, press on the sync dependencies button

Gradle project dependency not working

Can some one please help me in below:
I am using RTC and checkout Gradle project, but at the end when I am checking the properties and looking for source folder for my build, I am getting nothing.
Also I am not send the repository specific Gradle jars. What i am doing wrong?
I tried including external jars but no luck as their are too many jars.
Error: project is not at all building.
right click on your project then configure and convert it to gradle project.
Refresh and you will see all dependencies.

Using maven and Intellij IDEA, how can I modify a dependency without needing to manually install it every time?

I'm using Intellij-IDEA 11. If there's a solution that works in 12, I'd be willing to upgrade for that.
I built a library that many projects depend on but the library changes often. This library is added to my project's pom.xml as a normal dependency:
<dependency>
<groupId>my.company</groupId>
<artifactId>MyLibrary</artifactId>
</dependency>
This is a typical series of steps I need to take when I add a feature to my project:
Modify some code in my project
Modify some code in the library I depend on
Check to see if the feature works
If not, repeat
Outside of my IDE (which happens to be Intellij-IDEA), this is a straight forward process: I add step 2.5 which is to cd into the dependency's project folder and then mvn install the library.
But I don't know a convenient way to do this in Intellij-IDEA. Ideally, I'd modify the source of the library inside Intellij, click the green play button and the IDE would figure out to use the modified sources of the library.
Right now, since the library is a dependency, it just uses what's already in my local repo. So modifying the source of the library doesn't have an affect until I manually mvn install it.
Note: I've figured out a trick that seems to work. If I modify the project's parent pom to include the library as a maven module and then include the same library as an intellij module, it uses that source instead of the jar in my local repo. But I don't like this solution because I'd never want to commit that modified pom (because the module has to point to a file system path that only exists on my local file system).
I've found a bug in the Intellij-IDEA bug tracker that seems to relate to this: http://youtrack.jetbrains.com/issue/IDEA-25146
I found out a way to do this. First, you add the library's pom.xml in the Maven Projects tool window. Then you Edit your configurations so that they run the install goal of your library. And image of how to do this is provided below.
Click here for a full sized link
Open module setting (F4 on a module), go to Modules, select the dependencies tab in module that depepends on your library.
If the library is a module add a module dependency
If the library isn't a module, I assume it gets built and put somewhere, add that directory to the module dependencies.
The higher up the list the higher its priority
I've similar architecture and here is what I do (and it works very well).
Create an IDEA maven project based on the pom.xml of my main project (the project using the frequently changing library).
Add maven project to my main project (click on the "+" icon in the maven projects tab and choose the pom.xml of my frequently changing library)
EDIT
note: all the modules (from the library and from the main project) have a *-SNAPSHOT version
In more details, the pom.xml of my library project :
<groupId>com.company</groupId>
<artifactId>mylibrary</artifactId>
<version>2.0.1-SNAPSHOT</version>
And the pom.xml of my main project
<groupId>com.company</groupId>
<artifactId>myproject</artifactId>
<version>1.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>mylibrary</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
I think that IDEA is smart enough to see that the dependency is a SNAPSHOT and that this library is in the current IDEA project (i.e. same IDEA window)... and so IDEA don't look in the local repo since the SNAPSHOT is in the current "workspace".
Hope it clarify the situation.
If I need to run something, I have different options either
defining a new maven run configuration in IDEA to run any maven goal (from any pom.xml in my IDEA project) with any profile.
defining a simple unit test configuration in IDEA (not directly linked with maven except that the classpath is derived from the classpath defined in pom.xml)
defining a new Tomcat/JBoss configuration in IDEA and deploying some artifact in it. (IDEA detect deployable artifacts -like war or ejb- from the pom.xml)
I have the same scenario than you and I am using Intellij 2016.02.
Here is how I solved it:
1 - On Intellij open the maven panel going to View -> Tool Windows -> Maven Projects, then click at the plus green button (add maven project) and select the pom.xml file from the dependency project
2 - On Run/Debug configuration settings, add a before launch task as a maven goal, choosing the Working Directory of the dependency project and in command line just type "install".
3 - Now edit anything in your dependency project, and redeploy your main application, and the changes may affect.
EDITED:
I found a new solution, and it's solved the "update classes and resources" downside, here is what I did:
1 - Do the first step from the previous solution, but remove the install goal from before launch task if you add it on step 2.
2 - Edit the exploded artifact, and add the dependency project "compiled output" element from "Available elements" panel to output left panel.
Changes may work without need to install, and now my "Update classes and resources" works like a charm :)

IntelliJ steps through the wrong lines when debugging remote Java application

I tried to remote debug a maven plugin for a liquibase project with Intellij. IDEA is highlighting the wrong source code line.
I manually built and installed the plugin in my local maven repository from sources in my Intellij project. Intellij version is 11.1.3 and maven version is 3.0.4 running on Ubuntu 12.04.
For debugging the maven plugin I used mvnDebug comand.
If someone has any ideas please give me some advice. I'm not too used to remote debugging (in fact this is the second time I've done this).
For me, whenever IntelliJ is highlighting the wrong line, it was always because the version of the JAR/classes being used to run the application differs from my source files - i.e. different version of the sources were used to build the JAR and/or classes.
You are going to have to be sure that you are working from the exact source that was used to build the classes you are debugging.
You can verify this by looking at the classpath being used to launch the application, locating the JAR file or classes directory that contains the classes you are debugging, and verifying that they were built from the sources you are inspecting.
Note that when you are debugging third-party libraries, you often can download the "sources" jar (see IntelliJ2-IDEA get Maven-2 to download source and documentation).
If you stumbled across this post, and sure that the source and JAR are the same code, then this could be your problem.
http://youtrack.jetbrains.com/issue/IDEA-8021
Instead of doing remote debugging you can run the plugin directly from IntelliJ.
Have the liquibase plugin project loaded in IntelliJ by just pointing at the pom.xml.
Choose Edit Configurations...
Press the + button to Add New Configuration.
Select Maven.
Enter the Working directory to the project you want to run the plugin on.
Enter the Command line. Could be process-sources, compile or liquibase:status depending on what you want to do.
Press OK
Set a breakpoint in the Liquibase Mojo.
Now you can start this configuration by pressing Shift+F9.
Maven will start and finally you will see that your plugin is waiting at the breakpoint!
Make sure that you have defined the plugin in the target pom.xml with correct version and also that you build the plugin before launching it. You can ensure that by enabling Make in the Before Launch pane.

Resources