I would like to take advantage of the features that Maven provides for managing dependencies in a project. My brief understanding of how Maven works is that it will aquire the JARs needed and then build the project with these libraries.
Currently I have a simple POM file set up as a test:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jamesgoodwin.test</groupId>
<artifactId>com.jamesgoodwin.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.0.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
To manage dependencies, I usually add the project or JAR to the build path and then i'll be able to build my project..
But when using M2Eclipse the dependencies are not added automatically to the build path. Is there any configuration to let Eclipse know that the Maven is managing the dependencies?
If you right-click on your project, there should be an option under "maven" to "enable dependency management". That's it.
if you execute
mvn eclipse:clean
followed by
mvn eclipse:eclipse
if will prepare the eclipse .classpath file for you. That is, these commands are run against maven from the command line i.e. outside of eclipse.
I'm assuming you are using m2eclipse as you mentioned it. However it is not clear whether you created your project under Eclipse or not so I'll try to cover all cases.
If you created a "Java" project under Eclipse (Ctrl+N > Java Project), then right-click the project in the Package Explorer view and go to Maven > Enable Dependency Management (depending on the initial project structure, you may have modify it to match the maven's one, for example by adding src/java to the source folders on the build path).
If you created a "Maven Project" under Eclipse (Ctrl+N > Maven Project), then it should be already "Maven ready".
If you created a Maven project outside Eclipse (manually or with an archetype), then simply import it in Eclipse (right-click the Package Explorer view and select Import... > Maven Projects) and it will be "Maven ready".
Now, to add a dependency, either right-click the project and select Maven > Add Dependency) or edit the pom manually.
PS: avoid using the maven-eclipse-plugin if you are using m2eclipse. There is absolutely no need for it, it will be confusing, it will generate some mess. No, really, don't use it unless you really know what you are doing.
Add this to .classpath file ..
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Thx
Right click on the project Configure > convert to Maven project
Then you can see all the Maven related Menu for you project.
I did like this..
Right click on the project--> configure-->convert to maven project.
Right click on the project-->maven-->add dependencies.
In Eclipse (Mars) go to:
Project Properties --> Maven. Ensure that "Resolve dependencies from workspace projects" is disabled.
I did not found the maven or configure menus but found the following button that solved my problem:
When m2eclipse is installed properly, it should add dependencies automatically.
However, you should generate the eclipse project files by entering:
mvn eclipse:m2eclipse
or, alternatively if you don't use m2eclipse:
mvn eclipse:eclipse
I had a slight variation that caused some issues - multiple sub projects within one project. In this case I needed to go into each individual folder that contained a POM, execute the mvn eclipse:eclipse command and then manually copy/merge the classpath entries into my project classpath file.
For newer Eclipse versions (>=Mars) right click on project > configure > convert to Maven project
Adding my answers for a couple of reasons:
Somehow none of the answers listed directly resolved my problem.
I couldn't find "Enable dependency management" under Maven. I'm using Eclipse 4.4.2 build on Wed, 4 Feb 2015.
What helped me was another option under Maven called as "Update Project" and then when I click it this window opens which has a checkbox that says "Force update of Snapshot/Releases". The real purpose of this checkbox is different I know but somehow it resolved the dependencies issue.
None of that solved my problem. but what I did was if click on the pom.xml, there is a tab at the bottom named dependencies. in this tab it is split into 2 section, one called dependencies and one called dependency management. select every thing in the dependency section and click add to be under the dependency management control. close and reopen your project.
Maybe you could look into maven-eclipse-plugin instead of M2Eclipse.
There you basically add maven-eclipse-plugin configuration to your pom.xml and then execute mvn eclipse:eclipse which will generate the required .project and .classpath files for Eclipse. Then you'll have the correct build path in Eclipse.
Make sure your POM follows the naming convention, and is named in lowercase lettering as pom.xml and NOT POM.xml.
In my case all was right, but Eclipse still complained when trying to Right-click and Update project configuration - told me that the POM could not be read. Changed the name to lowercase - pom.xml from POM.xml - and it worked.
I met this issue too. When I add dependencies in the pom.xml, I checked in the local folder /Users/xyz/.m2/ and the jars are already downloaded there, but cann't added the the buildpath of the eclipse.
My eclipse Version: Mars.2 Release (4.5.2)
right click project > Maven > Enable Workspace Resolution
And this solved my issue.
Typically, you can copy the .classpath file from a working project since there isn’t anything project specific here assuming you’re structured as a standard Maven project.
This worked for me in Eclipse Oxygen (4.7.0):
Right click Project -> Maven -> Select Maven Profiles... then check the Repository Proxy box, press OK.
Related
I just imported a project from subversion to IntelliJ IDEA 11 - it's a maven project. But I have a problem in maven library dependencies so that I can't include all maven dependencies automatically - IDEA shows dependency errors only when I open that class/ Thats what I get here:
So I want all dependencies to be added automatically - is that possible or do I have to go through all class files to identify and add maven dependencies?!
UPDATE: After doing some modifications I found how to resolve my problem in some way. Thats what I did:
but I think logically it will not include and check new dependencies ahead?!... Is there any settings area for this in intelliJ - auto export dependencies to classpath?
IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.
When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.
You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".
If that doesn't help, then I would suggest to make a full clean-up and start again:
Close your project window (and IntelliJ) and remove all *.iml files and all .idea folders (there should be one per module)
Run mvn clean install from the command line
Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import
IntelliJ 2016 Update:
The Import Maven Projects automatically setting has been moved to Build, Execution, Deployment > Build Tools > Maven > Importing in your IntelliJ preferences.
Fix before IntelliJ 14
File [menu] -> Settings -> maven -> importing and uncheck "use maven3 to import project"
ref: http://youtrack.jetbrains.com/issue/IDEA-98425 (which may have a few other ideas too)
Fix IntelliJ 15+
Ran into this again, with IntelliJ 15 this time, which has no "use maven3 to import" option available anymore. The cause was that sometimes IntelliJ "doesn't parse maven dependencies right" and if it can't parse one of them right, it gives up on all of them, apparently. You can tell if this is the case by opening the maven projects tool window (View menu -> Tool Windows -> Maven Projects). Then expand one of your maven projects and its dependencies. If the dependencies are all underlined in red, "Houston, we have a problem".
You can actually see the real failure by mousing over the project name itself.
In my instance it said "Problems: No versions available for XXX" or "Failed to read descriptor for artifact org.xy.z" ref: https://youtrack.jetbrains.com/issue/IDEA-128846
and
https://youtrack.jetbrains.com/issue/IDEA-152555
It seems in this case I was dealing with a jar that didn't have an associated pom file (in our maven nexus repo, and also my local repository). If this is also your problem, "urrent work around: if you do not actually need to use classes from that jar in your own code (for instance a transitive maven dependency only), you can actually get away with commenting it out from the pom (temporarily), maven project reload, and then uncomment it. Somehow after that point IntelliJ "remembers" its old working dependencies. Adding a maven transitive exclude temporarily might also do it, if you're running into it from transitive chain of dependencies."
Another thing that might help is to use a "newer version" of maven than the bundled 3.0.5.
In order to set it up to use this as the default, close all your intellij windows, then open preferences -> build, execution and deployment -> build tools -> maven, and change the maven home directory, it should say "For default project" at the top when you adjust this, though you can adjust it for a particular project as well, as long as you "re import" after adjusting it.
Clear Caches
Deleting your intellij cache folders (windows: HOMEPATH/.{IntellijIdea,IdeaC}XXX linux ~/.IdeaIC15) and/or uninstalling and reinstalling IntelliJ itself. This can also be done by going to File [menu] -> Invalidate Caches / Restart.... Click invalidate and restart. This will reindex your whole project and solve many hard-to-trace issues with IntelliJ.
When importing the project, select pom.xml instead of the project directory. It should work.
Try to Re-Import the project from the Maven Projects panel in IntelliJ IDEA. It should download and configure all the dependencies defined in your pom.xml automatically.
If download doesn't work from IDEA for some reason, try mvn install from the command line and see if the dependencies can be fetched.
Of course all the required dependencies and any custom repositories must be defined directly in the pom.xml file.
For IntelliJ 2016-2.4 (and I believe other new-ish versions):
View > Tool Windows > Maven Projects
In the newly revealed toolbar, select Maven settings (icon of a toolset).
When this screen opens, expand the Maven menu and click 'Importing'
Here, click "Import Maven projects automatically." Also ensure that the 'JDK for Importer' option matches the JDK version you mean to use.
Click OK. Now go to the red dependency in your pom.xml, select the red lightbulb, and click 'Update Maven indices'.
What helped me:
Navigage:
Settings | Build, Execution, Deployment | Maven
Specify "Maven home directory" - the place you installed the maven
If certain maven modules are not compiling check if their pom.xml is on the "ignored files" list. In IntelliJ goto
preferences -> project settings -> maven -> ignored files
and check if the related pom.xml is ignored.
I had the same issue and tried all the answers mentioned here, none worked.
The simple solution is go to your project folder and delete all the .idea and .iml files and restart the IntelliJ ide. It works. No need to do anything with the settings.
Open IntelliJ Idea, Go to
File > Other Settings > Default Settings... > Maven (Preferences) > Importing or|
Preferences > Maven > Importing
Click on Enable Auto-import in the console.
When you create a new project you simply need to choose the option:
...
Import project from external model
Create IDEA project structure over existing external model (Eclipse, Maven...)
...
You'll find it pretty straight forward from there.
And in your case you can close your project and simply create a new one. Choose your project's directory, which will override it, making it a Maven project.
Importing Maven dependencies may not work if you import the same path several times. This may happen automatically after importing an existing maven project. I can't figure out why this happens, so I'm inclined to think it is a bug.
For example, if my project is
hibernate
src/main
src/test
the three paths may be imported as top nodes:
hibernate
src/main
src/test
If such is the case, the dependencies appear to be right, but they won't be used until you remove the superfluous paths (in this case, src/main and src/test). Once you do this, refresh and click Build > Rebuild Project. IDEA will pick up the dependencies.
A symptom of this problem is that IDEA warns you of a duplicated path when you manually check a library (second screenshot in the question).
There are several ways to re-read the dependencies in case you need it. If you go to the “Maven Projects” tab, there is a “Reimport All Maven Projects” icon at the top left of the tab. If you suspect IDEA became confused you can click on File > Invalidate Caches.
First check path Specified for User Settings file: in Settings -> Build,Execution,Development -> Build Tools -> Maven .
The field should have path of the settings.xml of your maven. Also the settings.xml should have correct path of remote repository.
Go into your project structure, under project Settings, Modules, select the dependencies table. For each dependency, change the scope from 'Test' to 'Compile'.
If in the lower right corner it says "2 processes running..." or similar, you may just need to wait for that to finish, since it may take time to download all the jars.
Reimport the project. If you install maven plugin you can use this.
Right click on the project -> Maven -> Reimport
I had a similar issue, in my case I am using a custom settings.xml which was not picked from IntelliJ.
Solution:
File > Settings > Build, Execution, Deployment > Maven: User settings file (chose here my custom settings.xml).
IntelliJ 2020.3.3
This one did it for me.
Build, Execution, Deployment > Build Tools.
Change "Reload project after changes in the build scripts":
from default "External Changes" to "Any Changes"
With this, it took a while for the project to rebuild but now I can see Maven dependencies in IntelliJ:
I ran into the problem that some subdependencies couldn't be resolved in IntelliJ 2016.3.X. This could be fixed by changing the Maven home directory in Settings > Build, Execution, Deployment > Build Tools > Maven from Bundled (Maven 3) to /usr/share/maven.
After that all subdependencies got resolved as in previous IntelliJ versions.
In my case, path for JAVA used by MAVEN was not set as JAVA_HOME as configured on the machine. Hence, it was not even trying to download the dependencies.
Steps I followed which solved this issue,
Checked for JAVA path , Settings >> Build >> Build Tools >> Importing >> JDK for importer. Pointed it to JAVA_HOME.
mvn clean install -U
Used above command to force the dependencies download.
Re imported Maven Projects
So I was also facing this problem in lots of my organisation's codebase. On addition to the answers suggested above, we can tweak around with the allocation pool memory of the jvm. This is because, the volume of the dependencies brought in large codebases may be overwhelming for the jvm for IDE to build the project completely. Hence tried increasing XMX value and it worked! Added -Xmx3072 to resolve the issue of "not building" my Java project in IntelliJ
Maven - Reimport did not work for me.
I have Spring project in STS(Eclipse) and my solution is to import project to IDEA like so:
1) File - New - Project from Existing Sources... - select directory - choose Eclipse.
2) Set Maven autoimport to true in settings.
3) Then right click in pom.xml and choose Add as Maven Project.
After this it has imported everything.
I had the similar issue with my macbook, just did a small change in pom.xml and it started downloading all dependencies:
Earlier dependencies were written as below for my windows machine:
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
I just removed the <dependencies> and </dependencies> tags and it started downloading all the dependencies:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
I am not sure it will work for you or not.. but worked fine for me.
Thanks
Deleting the .idea folder from the project directory, and then re-importing the project as a Maven project is what worked for me.
Invalidate Caches worked for me:
File > Invalidate Caches
Checks:
Clear file system cache and Local History
Clear downloaded shared indexes
Then Invalidate and Restart
I solved this issue by updating my settings.xml file with correct mirror config, seems that intellij will try to download meta-data from repository every time the maven module imported.
Hijacking a bit to add what ended up working for me:
Go into the Maven Projects sidebar on the right edge of the IDE, and verify that your dependencies are listed correctly under your module there. Assuming they are, just ask IDEA to reimport then (the first button at the top, looks like two blue arrows forming a counter-clockwise circle).
Once I did that, and let IDEA reload the project for me, all my dependencies were magically understood.
For reference: this was with IDEA 13.1.2
I faced the same problem and tried everything suggested which did not solve the issue, I was using Intellij version 13.1.3
Finally after spending more than couple of hours trying to fix it, I decided to try an upgraded version and opened the project in version 14.1.4 which ultimately resolved the issue. I would think this as a probable bug in the previous version.
I hope this helps!
I was able to resolve it by removing unnecessary modules from Project Settings -> Modules list.
It turns out these additional modules were created automatically by IntelliJ IDEA when I created the IntelliJ project by importing from the project folder (instead of by opening pom.xml). Then, after declaring the project as Maven project, proper modules were created, and existing modules were conflicting with them. It is also possible to exclude those modules during project creation.
In my case, one of the modules was ignored for some reason.
To resolve that: Right click the problematic module and choose "Unignore Projects".
You might be working under a company's internal network.
If so, to download or add external Maven dependencies your settings.xml file under user/<username>/.m2 folder might need to be updated.
Contact your administrator to provide the right settings.xml file and then paste it into you .m2 folder.
I have the current version of the dependency successfully installed in the local mvn .m2 registry with mvn clean install (confirmed by cd into .m2 repository).
I then modified the pom.xml of the project to include the new version number:
<dependency>
<groupId>com.xyz.lib</groupId>
<artifactId>xyz-lib-abc-model</artifactId>
<version>1.4.0-SNAPSHOT</version>
</dependency>
Maven was able to build successfully with 1.4.0-SNAPSHOT, but when I accessed the project in IntelliJ, it linked to an old version (0.1.1-SNAPSHOT) instead of the current version.
When I checked the dependency tree using `mvn dependency:tree, I have:
[INFO] +- com.xyz.lib:xyz-lib-abc-model:jar:1.4.0-SNAPSHOT:compile
Which looks correct to me.
I have tried using <dependencyManagement> but then it makes the project failed to build, and failed to detect the model.
Anyone knows what's going on and how to get maven to pull the correct version?
Thank you in advance!
Try re-importing the dependencies from local m2 in IntelliJ like :
Open the project view in IntelliJ
Right click the pom.xml file and
select Maven - Reimport If this works for you IntelliJ will add the
dependencies to the project
Check the if the dependencies you need are added in File - Project
Structure - Project Settings - Libraries and File - Project
Structure - Modules - Dependencies
I have seen this issue with IntelliJ.
If you don't need the old version anymore, you can cd to .m2 directory and delete the older version manually.
But you need to keep the both versions, you can open the project as a fresh project using the pom.xml. This will solve the issue.
Try the following approach:
Close the project in IntelliJ
File --> Open ...
Find pom.xml of your project, not the idea project files
Open this pom.xml. It will re-build all the dependency model in accordance with the information found in this new pom.xml (that I assume doesn't have an old dependency anymore).
DependencyManagement section is irrelevant in this case - mention it because you've said in the question that you've tried this - so don't bother, it will save you some time :)
my first guess goes to the used maven type in your IDEA is not the one that you use in the terminal. :)
You can set up the installed maven instead of the bundled one.
Or another solution is that you proceed a “refresh/reimport” in pom.xml. It will investigate the classpath based on your pom.xml and refresh the ones that needed.
You should see the "Reimport button here
If you don't see Maven at all, that means. you haven't added your project to IDEA as a Maven project.
Please then do the following
1. Right Click on pom.xml
2. 2. Add as a maven project
I just imported a project from subversion to IntelliJ IDEA 11 - it's a maven project. But I have a problem in maven library dependencies so that I can't include all maven dependencies automatically - IDEA shows dependency errors only when I open that class/ Thats what I get here:
So I want all dependencies to be added automatically - is that possible or do I have to go through all class files to identify and add maven dependencies?!
UPDATE: After doing some modifications I found how to resolve my problem in some way. Thats what I did:
but I think logically it will not include and check new dependencies ahead?!... Is there any settings area for this in intelliJ - auto export dependencies to classpath?
IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.
When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.
You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".
If that doesn't help, then I would suggest to make a full clean-up and start again:
Close your project window (and IntelliJ) and remove all *.iml files and all .idea folders (there should be one per module)
Run mvn clean install from the command line
Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import
IntelliJ 2016 Update:
The Import Maven Projects automatically setting has been moved to Build, Execution, Deployment > Build Tools > Maven > Importing in your IntelliJ preferences.
Fix before IntelliJ 14
File [menu] -> Settings -> maven -> importing and uncheck "use maven3 to import project"
ref: http://youtrack.jetbrains.com/issue/IDEA-98425 (which may have a few other ideas too)
Fix IntelliJ 15+
Ran into this again, with IntelliJ 15 this time, which has no "use maven3 to import" option available anymore. The cause was that sometimes IntelliJ "doesn't parse maven dependencies right" and if it can't parse one of them right, it gives up on all of them, apparently. You can tell if this is the case by opening the maven projects tool window (View menu -> Tool Windows -> Maven Projects). Then expand one of your maven projects and its dependencies. If the dependencies are all underlined in red, "Houston, we have a problem".
You can actually see the real failure by mousing over the project name itself.
In my instance it said "Problems: No versions available for XXX" or "Failed to read descriptor for artifact org.xy.z" ref: https://youtrack.jetbrains.com/issue/IDEA-128846
and
https://youtrack.jetbrains.com/issue/IDEA-152555
It seems in this case I was dealing with a jar that didn't have an associated pom file (in our maven nexus repo, and also my local repository). If this is also your problem, "urrent work around: if you do not actually need to use classes from that jar in your own code (for instance a transitive maven dependency only), you can actually get away with commenting it out from the pom (temporarily), maven project reload, and then uncomment it. Somehow after that point IntelliJ "remembers" its old working dependencies. Adding a maven transitive exclude temporarily might also do it, if you're running into it from transitive chain of dependencies."
Another thing that might help is to use a "newer version" of maven than the bundled 3.0.5.
In order to set it up to use this as the default, close all your intellij windows, then open preferences -> build, execution and deployment -> build tools -> maven, and change the maven home directory, it should say "For default project" at the top when you adjust this, though you can adjust it for a particular project as well, as long as you "re import" after adjusting it.
Clear Caches
Deleting your intellij cache folders (windows: HOMEPATH/.{IntellijIdea,IdeaC}XXX linux ~/.IdeaIC15) and/or uninstalling and reinstalling IntelliJ itself. This can also be done by going to File [menu] -> Invalidate Caches / Restart.... Click invalidate and restart. This will reindex your whole project and solve many hard-to-trace issues with IntelliJ.
When importing the project, select pom.xml instead of the project directory. It should work.
Try to Re-Import the project from the Maven Projects panel in IntelliJ IDEA. It should download and configure all the dependencies defined in your pom.xml automatically.
If download doesn't work from IDEA for some reason, try mvn install from the command line and see if the dependencies can be fetched.
Of course all the required dependencies and any custom repositories must be defined directly in the pom.xml file.
For IntelliJ 2016-2.4 (and I believe other new-ish versions):
View > Tool Windows > Maven Projects
In the newly revealed toolbar, select Maven settings (icon of a toolset).
When this screen opens, expand the Maven menu and click 'Importing'
Here, click "Import Maven projects automatically." Also ensure that the 'JDK for Importer' option matches the JDK version you mean to use.
Click OK. Now go to the red dependency in your pom.xml, select the red lightbulb, and click 'Update Maven indices'.
What helped me:
Navigage:
Settings | Build, Execution, Deployment | Maven
Specify "Maven home directory" - the place you installed the maven
If certain maven modules are not compiling check if their pom.xml is on the "ignored files" list. In IntelliJ goto
preferences -> project settings -> maven -> ignored files
and check if the related pom.xml is ignored.
I had the same issue and tried all the answers mentioned here, none worked.
The simple solution is go to your project folder and delete all the .idea and .iml files and restart the IntelliJ ide. It works. No need to do anything with the settings.
Open IntelliJ Idea, Go to
File > Other Settings > Default Settings... > Maven (Preferences) > Importing or|
Preferences > Maven > Importing
Click on Enable Auto-import in the console.
When you create a new project you simply need to choose the option:
...
Import project from external model
Create IDEA project structure over existing external model (Eclipse, Maven...)
...
You'll find it pretty straight forward from there.
And in your case you can close your project and simply create a new one. Choose your project's directory, which will override it, making it a Maven project.
Importing Maven dependencies may not work if you import the same path several times. This may happen automatically after importing an existing maven project. I can't figure out why this happens, so I'm inclined to think it is a bug.
For example, if my project is
hibernate
src/main
src/test
the three paths may be imported as top nodes:
hibernate
src/main
src/test
If such is the case, the dependencies appear to be right, but they won't be used until you remove the superfluous paths (in this case, src/main and src/test). Once you do this, refresh and click Build > Rebuild Project. IDEA will pick up the dependencies.
A symptom of this problem is that IDEA warns you of a duplicated path when you manually check a library (second screenshot in the question).
There are several ways to re-read the dependencies in case you need it. If you go to the “Maven Projects” tab, there is a “Reimport All Maven Projects” icon at the top left of the tab. If you suspect IDEA became confused you can click on File > Invalidate Caches.
First check path Specified for User Settings file: in Settings -> Build,Execution,Development -> Build Tools -> Maven .
The field should have path of the settings.xml of your maven. Also the settings.xml should have correct path of remote repository.
Go into your project structure, under project Settings, Modules, select the dependencies table. For each dependency, change the scope from 'Test' to 'Compile'.
If in the lower right corner it says "2 processes running..." or similar, you may just need to wait for that to finish, since it may take time to download all the jars.
Reimport the project. If you install maven plugin you can use this.
Right click on the project -> Maven -> Reimport
I had a similar issue, in my case I am using a custom settings.xml which was not picked from IntelliJ.
Solution:
File > Settings > Build, Execution, Deployment > Maven: User settings file (chose here my custom settings.xml).
IntelliJ 2020.3.3
This one did it for me.
Build, Execution, Deployment > Build Tools.
Change "Reload project after changes in the build scripts":
from default "External Changes" to "Any Changes"
With this, it took a while for the project to rebuild but now I can see Maven dependencies in IntelliJ:
I ran into the problem that some subdependencies couldn't be resolved in IntelliJ 2016.3.X. This could be fixed by changing the Maven home directory in Settings > Build, Execution, Deployment > Build Tools > Maven from Bundled (Maven 3) to /usr/share/maven.
After that all subdependencies got resolved as in previous IntelliJ versions.
In my case, path for JAVA used by MAVEN was not set as JAVA_HOME as configured on the machine. Hence, it was not even trying to download the dependencies.
Steps I followed which solved this issue,
Checked for JAVA path , Settings >> Build >> Build Tools >> Importing >> JDK for importer. Pointed it to JAVA_HOME.
mvn clean install -U
Used above command to force the dependencies download.
Re imported Maven Projects
So I was also facing this problem in lots of my organisation's codebase. On addition to the answers suggested above, we can tweak around with the allocation pool memory of the jvm. This is because, the volume of the dependencies brought in large codebases may be overwhelming for the jvm for IDE to build the project completely. Hence tried increasing XMX value and it worked! Added -Xmx3072 to resolve the issue of "not building" my Java project in IntelliJ
Maven - Reimport did not work for me.
I have Spring project in STS(Eclipse) and my solution is to import project to IDEA like so:
1) File - New - Project from Existing Sources... - select directory - choose Eclipse.
2) Set Maven autoimport to true in settings.
3) Then right click in pom.xml and choose Add as Maven Project.
After this it has imported everything.
I had the similar issue with my macbook, just did a small change in pom.xml and it started downloading all dependencies:
Earlier dependencies were written as below for my windows machine:
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
I just removed the <dependencies> and </dependencies> tags and it started downloading all the dependencies:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
I am not sure it will work for you or not.. but worked fine for me.
Thanks
Deleting the .idea folder from the project directory, and then re-importing the project as a Maven project is what worked for me.
Invalidate Caches worked for me:
File > Invalidate Caches
Checks:
Clear file system cache and Local History
Clear downloaded shared indexes
Then Invalidate and Restart
I solved this issue by updating my settings.xml file with correct mirror config, seems that intellij will try to download meta-data from repository every time the maven module imported.
Hijacking a bit to add what ended up working for me:
Go into the Maven Projects sidebar on the right edge of the IDE, and verify that your dependencies are listed correctly under your module there. Assuming they are, just ask IDEA to reimport then (the first button at the top, looks like two blue arrows forming a counter-clockwise circle).
Once I did that, and let IDEA reload the project for me, all my dependencies were magically understood.
For reference: this was with IDEA 13.1.2
I faced the same problem and tried everything suggested which did not solve the issue, I was using Intellij version 13.1.3
Finally after spending more than couple of hours trying to fix it, I decided to try an upgraded version and opened the project in version 14.1.4 which ultimately resolved the issue. I would think this as a probable bug in the previous version.
I hope this helps!
I was able to resolve it by removing unnecessary modules from Project Settings -> Modules list.
It turns out these additional modules were created automatically by IntelliJ IDEA when I created the IntelliJ project by importing from the project folder (instead of by opening pom.xml). Then, after declaring the project as Maven project, proper modules were created, and existing modules were conflicting with them. It is also possible to exclude those modules during project creation.
In my case, one of the modules was ignored for some reason.
To resolve that: Right click the problematic module and choose "Unignore Projects".
You might be working under a company's internal network.
If so, to download or add external Maven dependencies your settings.xml file under user/<username>/.m2 folder might need to be updated.
Contact your administrator to provide the right settings.xml file and then paste it into you .m2 folder.
I have a project in IntelliJ IDEA which was created with Maven. I then specified a set of dependencies and external repositories in the Pom.xml file.
The project builds fine on command line if I do mvn install. When I open any of the code files in the IDE though it says all the classes handled by Maven dependencies aren't recognized - as it would for a normal project if I never added the required JARs to the build path.
I know in my Eclipse Maven projects (rather than IntelliJ) it usually shows an extra directory on the left which says "Maven Dependencies" and lists the JARs pulled in via maven. I don't see that here. What am I doing wrong?
Here's what my screen looks like:
Right click on the pom.xml -> Add as Maven project -> Reimport
For some reason re-import did not do the trick. After looking at this:
http://www.jetbrains.com/idea/webhelp/maven-importing.html
I set auto-import and then the problem went away though; hopefully it helps someone else. Thanks for the ideas everyone :).
After installing IntelliJ IDEA on a new computer I found myself with the same issue.
I had to update the remote maven repository. (Settings > Maven > Repositories)
Both local and remote repos needed to be updated. The remote one wasn't updated ever before this. After a restart everything worked fine. You might have to reimport your project.
You could go to:
File > Settings > Build, Execution, Deployment > Build Tools > Maven
and check if your pom.xml is not in the "Ignored Files" list.
I was running into similar issues. For me it ended up being that I was importing the project incorrectly. I had been doing
import project
<navigate to existing project and click top level directory>
follow the wizard
What solved my maven problems was to do
import project
<navigate to existing project and click the pom.xml
follow the wizard
For me File>>Invalidate Cache/Restart>>Invalidate and Restart worked in IntelliJ
Idea cannot download all dependent jar packages using maven,try the following operations:
mvn -U idea:idea
then all the dependent jar packages are download from the maven repository
A simple reimport and/or update of the repositories via Intellij did not do the trick for me.
Instead I had to delete the complete ~/.m2/repository directory and let maven sort everything out by itself. Afterwards Maven -> Reimport finished it off.
I've encountered a similar issue after refactoring my maven project into different modules. Re-importing on it's own usually doesn't work, but I've found that deleting the .iml files and then re-importing usually does the trick.
Ran into the "same" issue some days ago. It might not be related as my issue was more specific to Spring boot but as I was struggling with it and tried every solution on this post I'm going to share my experience.
What I was trying to do is to add one of my spring boot app into another project as a maven dependency. The dependency was resolved but I couldn't access my classes.
When no packaging is declared, Maven assumes the default packaging is JAR.
The JAR generated by the Spring Boot Maven Plugin overrides the default one generated by Maven.
The solution was:
The solution that we found is to generate another JAR which will be used as a dependency to be imported from other projects.
The full article which helped me solve my issue.
Hope it helps someone.
For reasons I don't understand, in my case, I needed turn on setting "Always update snapshots" in Build, Executions, Deployment > Build Tools > Maven.
That made IntelliJ redownload dependencies and make it work.
In my case the problem was that the project was in maven2 while intellj was configured for maven3. Switching to maven2 in settings solved the problem
Might be useful to others that were still stuck like me.
None of the suggested fix worked. Actually, not before I fixed my main problem which was the installation location of maven.
In my case, I did not use the standard location. Changing that location in the maven settings (Settings/Maven/Maven home repository) did the trick.
My 2 cents.
Cache is causing problems! Make sure to do the following:
In your terminal, go to project/module:
mvn clean install
In your IntelliJ:
File > Invalidate Caches > Invalidate
Right click on project/module > Maven > Reimport
For my case I should have checked the work offline
Go to File>Settings >Build, Execution, Deployment >Build tools>Maven
Then check Work Offline
Worked for me:
mvn -U idea:idea
Since mvn -U updates the dependencies, check what mvn -U does: https://stackoverflow.com/a/26224957/6150881
Before this I have tried following steps but these have not helped:-
Deleted .idea and .iml file
Invalidate cache and restart
Maven -> Reimport .
This happened to me when I had mistakenly set my IntelliJ to power saving mode. Power Saving mode is displayed by battery icon with half empty charge. Disabling that fixed the problem.
This also happened to me after upgrading Intellij to 1.4.15. I tried to re-import the whole project with same result, but enabling Maven Auto Import did the tricks.
Looks like there are several, valid reasons why intelliJ would ignore a pom file.
None of the previous answers worked in my case, so here's what did work, in case someone else runs into this issue:
In this example, module3 was being completely ignored by IntelliJ. The pom.xml in that directory wasn't even being treated as a maven pom.
My project structure is like this:
myProject
module1
module2
module3
BUT, my (simplified) pom structure is like this:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>devs</groupId>
<artifactId>myProject</artifactId>
<version>0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>myProject</name>
<modules>
<module>module1</module>
<module>module2</module>
<modules>
<profiles>
<profile>
<id>CompleteBuildProfile</id>
<modules>
<module>module3</module>
</modules>
</profile>
</profiles>
</project>
To fix this, I modified the root <modules> element to add in module3 temporarily.
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<modules>
Next re-import the root pom, and IntelliJ will add the module.
When that's done, revert the pom. IntelliJ will ask if you also want to remove module3 from the project structure. Click No.
Bam! Done. Module3 works and I can run my Integration tests from IntelliJ again :D
The problem was caused for me by selecting the project directory to be Imported when first starting IntelliJ rather than the pom.xml file for the project.
Closing the problem project and then following the Import process again but choosing the pom.xml resulted in a fully working project in the IDE.
For me the problem seems to be a conflict with the maven helper plugin (https://plugins.jetbrains.com/plugin/7179?pr=idea).
I disable it, and it works again :)
Go to
File > Settings > Build, Execution, Deployment > Build Tools > Maven
and check the Maven home directory. This should be the same maven installation used for command line
For me, what did the trick was to add the dependencies in File > Project Settings > Modules > Dependencies.
Just delete your project's .idea folder and re-import your project in IntelliJ.
If you have any dependencies in pom.xml specific to your organisation than you need to update path of setting.xml for your project which is by default set to your user directory in Ubuntu : /home/user/.m2/settings.xml -> (change it to your apache-maven conf path)
Go to -> intellij settings -> build,Execution, Deployement -> Build Tools -> Maven -> User settings file
Restart, Invalid caches, outside building, none worked for me.
Only Reimport worked finally. For others sake, putting it as answer:
Right click the project > Maven > Reimport
While importing a New project :
1.To identify all the modules in a project as maven modules:
File --->New Project Settings -->Build Execution deployment -->build tools --> maven ---> importing ---> enable "search for projects recursively"
Option1: Right-click on the main project folder => Add Framework Support => Check Maven option
Option2: right-click on the pom.xml file and click on "Add as a maven project"
This happened when I was upgrading from Java from 8 to 11 and Spring version. All the dependencies in the maven section disappeared as if no pom file existed. Was able to find the issue by doing
mvn clean
It showed me that one of the dependencies was missing version tag and it needed one.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
After adding version to the above dependency it started showing up all the dependencies under maven section.
In my case the my maven home path was pointing to Bundled Maven 3 instead of where my .m2 folder was located, fixed it by going to File > Settings > Build, Execution and Deployment > Maven > Maven home path and adding C:/Program Files/apache-maven-3.5.4
I have a maven project which won't compile due to an unresolvable reference from another project's artifact.
When I run eclipse:eclipse and open it up it shows an auto fix suggestion of "Add project 'project2' to build path of 'project1'". If I click this everything works. So project1 can clearly see my project2 reference, but doesn't quite use it as expected.
However, once I delete all the files generated for eclipse the error resumes because whatever reference eclipse created has been removed. How can I get this project2 in the project1 build path manually. I already have it listed in the pom as below:
<dependency>
<groupId>group.id</groupId>
<artifactId>project2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In "Project properties > Maven" menu you should check "Resolve dependencies from Workspace projects".
When I run eclipse:eclipse[...]
This sounds like you are using the Maven Eclipse plugin. You should probably rather use m2e, which is the recommended way to integrate with Maven now. This will also obviate the need to run mvn eclipse:eclipse. Instead, just import your Maven project into Eclipse, and it will pick up everything automatically.
After you set "Resolve dependencies from Workspace projects" as described in polypiel's answer, things should just work (TM).
If you have maven nature to both your projects, you should do mvn clean install to both the projects, so they will be installed in your local repository and will be available for other projects to use as dependencies. Or just right click to both the projects in eclipse and choose Run As --> Maven install