Add all local maven repository jars as libraries

Answered

I have a project that has a lot of maven dependencies coming from a local repository. I have configured the project to use the correct directory, and my settings.xml is configured properly. The main functionality I'm trying to achieve is looking up the base code from a class while in the main project. For example,

 

import com.org.xyz.ExampleClass;

 

public static void main(String[] args) {

ExampleClass exampleClass = new ExampleClass();

exampleClass.doSomething();

}

 

I would like to have the ability to search "exampleClass" and find the base functionality of the class. Doing double shift or ctrl+shift+f do not reveal any of the code. The only way I can do this is by finding the .jar in the repository and adding it as a library. After doing this I can successfully find the code using double shift. This is not a difficult task, but my current project has over 100 .jars that my team nor I have the time to add individually. Is there a simple way of adding all of these .jars as libraries or perhaps an alternative to navigating the base code? 

0
6 comments

Is your project Maven based? You should know beforehand what dependencies will be needed in this project and add them into pom.xml.

To find which Maven dependency contains a certain class you can use external services like https://search.maven.org/ .

See also https://youtrack.jetbrains.com/issue/IDEA-197739 and the linked requests.

0
Avatar
Permanently deleted user

Hi Serge,

 

The project is maven based. The pom.xml uses a local repository as a dependency, any classes from the remote repository load fine. When the project is loaded using myEclipse, I can do something similar to the above example. However, when I use IntelliJ I cannot view the source code unless I add the .jars from the libraries within the repository.

 

This local repository is in C:\Maven\.m2\repository\ and has many directories with several .jars. If I want to search up source code within my project, I have to add that repository as a module and add each individual .jar as a library before it's searchable. If I run the project in debug, I can hit breakpoints within that source code, so I'm fairly confident that the project is in fact using that repository. 

 

My question is, is there a better way of adding these .jars as libraries or viewing the code? Finding every needed .jar and adding them separately takes a lot of times, and I frequently need to view the source code from those .jars.

 

0

>The pom.xml uses a local repository as a dependency, 

What is a dependency layout format in the local repository? Does it have corresponding pom file? Sources jar? If format is correct and the Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Importing | Automatically download -> Sources option is enabled IDE will automatically download/attach sources to the library. You can check if sources are attached in the library configuration:

>I have to add that repository as a module and add each individual .jar as a library before it's searchable.

Do you may be mean that these libraries - are local projects that you develop locally and publish to local maven repository and you want their sources to be included into current project? In this case you should add these projects to current project as Maven modules, see Link a Maven project.

0
Avatar
Permanently deleted user

I think I have figured out the root issue, but I cannot resolve it. 

 

The .jar sources are being added as libraries by Maven like what Andrey said. However, the pom.xml uses a range to find which version source .jar to use ([8.200.0, 8.200.999]). MyEclipse is able to search the directories using that range to find which .jar to add as a source. IntelliJ is defaulting to using 8.200.0 and pulling in .jar.lastUpdated for some source files that don't have a version 8.200.0.

0
Avatar
Permanently deleted user

Hey @... did you resolve the above issue?

0

@Priyank Aenugula could you please clarify how do you define such dependencies in pom.xml? We have a related issue logged: https://youtrack.jetbrains.com/issue/IDEA-66158.

0

Please sign in to leave a comment.