Reputation: 605
I'm using Intellij 14.0.3. I have imported some Maven modules which declares dependencies in their pom.xml files.
In the IDE, when I'm opening a class importing an object from that dependencies, the import is shown as "on error" such as any reference to that object in this class. When I click on the error and type alt + Enter, Intellij ask me to add the dependency from Maven to the Classpath.
Example:
In my pom I have:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.version}</version>
</dependency>
In my class I have the following import on error:
import org.joda.time.DateTime;
When I click alt + enter intellij ask me:
Add library Maven: 'joda-time:joda-time:2.1' to classpath
Why Intellij does not import Maven dependencies directly in the classpath? In Settings -> Maven -> Importing, I've checked "Import Maven projects automatically' but it still doesn't import dependencies. Try to "Make" the project with no success.
Thanks for the help.
Upvotes: 4
Views: 6053
Reputation: 4164
In my case, I had the dependencies marked with <scope>test</test>
and inside the test folder. Once I moved the files to the main folder, IntelliJ wouldn't find them anymore and I had to remove the test scope.
Upvotes: 0
Reputation: 605
I've finally found a solution.
When the project was initially imported my maven settings.XML was not the good one. I've changed the path of maven settings ones the workspace was imported ans it seems that it doesnt work very well. Perhaps a bug? ( intellij 14.0.3).
I've deleted m'y workspace, cloned it from git once a gain and imported as a Maven project taking care that Maven Settings were previously set.
Upvotes: 4
Reputation: 1076
You have to delete all files in .m2
folder. Then setup the setting.xml
file for maven like this.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
...
</settings>
Then import your maven project, the ide will automatically download the alldependencies
Upvotes: 1