Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven install error: Dependency could not be resolved

Tags:

maven

maven-3

I am using Maven 3.1.1. When I run mvn install I get the following error:

D:\spring source>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringDependencies 1.0
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.648s
[INFO] Finished at: Mon Dec 16 15:01:47 IST 2013
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-dependency-plugin:2.8 or one of it
s dependencies could not be resolved: Failed to read artifact descriptor for org
.apache.maven.plugins:maven-dependency-plugin:jar:2.8: Could not transfer artifa
ct org.apache.maven.plugins:maven-dependency-plugin:pom:2.8 from/to central (htt
p://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.mave
n.apache.org -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResoluti
onException

My pom.xml is:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spring-source-download</groupId>
  <artifactId>SpringDependencies</artifactId>
  <version>1.0</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
              <execution>
                <id>download-dependencies</id>
                  <phase>generate-resources</phase>
                    <goals>
                      <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                      <outputDirectory> ${project.build.directory}/dependencies </outputDirectory>
                    </configuration>
              </execution>
            </executions>
      </plugin>
    </plugins>
  </build>
</project>
like image 893
khateeb Avatar asked Dec 16 '13 10:12

khateeb


People also ask

Why Maven is not working in IntelliJ?

Maven dependencies imported incorrectly If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local .


5 Answers

Could not transfer artifact org.apache.maven.plugins:maven-dependency-plugin:pom:2.8 from/to central (http://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org

It seems like your maven cannot access remote central repository.

  • Check if you have an established internet connection.
  • Check if you can access default maven repo http://repo.maven.apache.org/maven2 in your browser.
  • Check if you have correct configuration in <repositories> and <proxies> in your your settings.xml
like image 142
arghtype Avatar answered Oct 13 '22 19:10

arghtype


This error comes due to the proxy settings.

First of all, check whether you are able to connect to maven repository(http://repo1.maven.org/maven2) from browser.

Then update Maven proxy setting create/update a settings.xml in .m2 directory with following details:

 <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>{your proxy server host name}</host>
      <port>{your proxy server port}</port>
      <nonProxyHosts>maven</nonProxyHosts>
    </proxy>
  </proxies>

Solution given by Maven community: http://maven.apache.org/guides/mini/guide-proxies.html

like image 22
TarunChhabra Avatar answered Oct 13 '22 21:10

TarunChhabra


This is caused by corrupted maven or plugins folder. To resolve this:

  1. Delete \.m2\repository\org\apache\maven
  2. mvn dependency:resolve -X
like image 29
Sampath Avatar answered Oct 13 '22 20:10

Sampath


Disconnect from VPN and then run the command.

like image 38
Andrew Koper Avatar answered Oct 13 '22 19:10

Andrew Koper


Where is my Settings.xml?

Windows users

It's in your C:/Users/<Username>/.m2/settings.xml

Also, this is for specific user. Global one can be present at :

<Maven-Installation-Directory>/conf/settings.xml

But changing the User one might solve the issue if you can't find the global one.

Also, equally important, go to Preferences in Eclipse/STS:

  • Goto Maven -> User Settings and verify if both global and user settings.xml files are mentioned in the properties, if not mention them by browsing.

1. Proxy Issue

Check Windows Proxy Setting. If there is any proxy which your computer is using then you need to add proxy settings in your settings.xml file too.

Just add this chunk of code in your settings.xml

<proxies>
   <proxy>
      <id>proxy-id</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>ca-something.net</host>
      <port>80</port>
      <nonProxyHosts>localhost|10.140.240.90.*</nonProxyHosts>
    </proxy>
  </proxies> 

2. Protocol Issue

Visit http://repo.maven.apache.org/: If it says Https required.

Then, you need to add this chunk of code to your settings.xml inside <mirrors>

<mirror>
  <id>central-secure</id>
  <url>https://repo.maven.apache.org/maven2</url>
  <mirrorOf>central</mirrorOf>
</mirror>

Now it should be good to go.

3. None of the above works

Try disconnecting any company private VPN and try mvn clean build.

like image 30
Sumit Badsara Avatar answered Oct 13 '22 21:10

Sumit Badsara