Import Maven dependencies in IntelliJ IDEA

2019-01-03 08:18发布

I have a small question about IntelliJ IDEA 11. I just imported a project from subversion - its 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:

enter image description 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: enter image description here

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 ?!

27条回答
趁早两清
2楼-- · 2019-01-03 08:38

Deleting the .idea folder from the project directory, and then re-importing the project as a Maven project is what worked for me.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-03 08:39

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.

查看更多
We Are One
4楼-- · 2019-01-03 08:40

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.

查看更多
老娘就宠你
5楼-- · 2019-01-03 08:40

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.

查看更多
戒情不戒烟
6楼-- · 2019-01-03 08:41

In maven the dependencies got included for me when I removed the dependencyManagement xml section and just had dependencies directly under project section

查看更多
Bombasti
7楼-- · 2019-01-03 08:41

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).

查看更多
登录 后发表回答