简体   繁体   中英

Why is maven looking for artifact in the wrong repo?

I'm defining a dependency in pom.xml in a Maven 3 project. Dependency is as follows:

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>el-impl</artifactId>
    <scope>runtime</scope>
    <version>2.2</version>
</dependency>

Repostory is described in pom as follows:

<repository>
    <id>java.net</id>
    <name>java.net</name>
    <url>http://download.java.net/maven/2</url>
</repository>

Artifact is indeed present in the repository. It's easy to check . Despite that, Maven is trying to obtain the artifact from repo1.maven.org . What could be the reason of this? Maybe I make some crucial mistake in defining repository access? Other dependencies seem to do fine.

Plugin org.mortbay.jetty:maven-jetty-plugin:6.1.26 or one of its 
dependencies could not be resolved: Could not find artifact 
org.glassfish.web:el-impl:jar:2.2 
in central (http://repo1.maven.org/maven2)

The repository that you have defined is used for dependencies, but not for plugins . Hence the error.

To address this, you need to define pluginRepositories :

<project>
    <!-- ... -->

    <pluginRepositories>
        <pluginRepository>
            <id>{repo.id}</id>
            <url>{repo.url}</url>
        </pluginRepository>
    </pluginRepositories>
</project>

As to where you should specify - in pom.xml or settings.xml, read this SO post .

You need to check your maven settings.xml (Look into Maven folder: M2_HOME/conf ).
The default repositories are defined there itself, and Maven central repository is taking precedence.

Define your repository in Maven's settings.xml like this:

<profiles>
<profile>
  ...
  <repositories>
    <repository>
      <id>Java Net</id>
      <name>Java Net</name>
      <releases>
        <enabled>false</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
        <checksumPolicy>fail</checksumPolicy>
      </snapshots>
      <url>http://download.java.net/maven/2</url>
      <layout>default</layout>
    </repository>
  </repositories>
  <pluginRepositories>
    ...
  </pluginRepositories>
  ...
</profile>

You can maybe overwrite the default Maven central repository location with yours if you don't want to do much configuration.

Cheers!

I had a similar problem however, another developer had set up a mirror in that I simply copy-pasted into my settings.xml file. Modifying the mirrorOf property to only include specific repos did the trick.

In my case, the real root issue was that the repo required authentication. However for some reason maven decided that it would be much better to not tell me that, and to instead use the first repo in the <repositories> list , and throw the Could not find artifact error for that repo.

After moving the repo that contained the package so it was the first one in the <repositories> list, it started showing me a "permission denied" message. Once maven was setup for authentication with the repo in question, the issue went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM