Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is maven downloading the same artifact multiple times?

Tags:

maven

nexus

I run a maven build and I see the same artifact downloaded several times. After a successful download from one repo, a download from another repo is attempted. Some downloads are (0 B at 0.0 KB/sec).

[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)
[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)
[INFO] Downloading: http://repo.spring.io/ext-release-local/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/milestone/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/snapshot/aopalliance/aopalliance/1.0/aopalliance-1.0.jar

The repository configuration:

 <repositories>
    <repository>
        <id>Myproject-group</id>
        <name>Myproject-group</name>
        <layout>default</layout>
        <url>https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/</url>
        <snapshots>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
        </snapshots>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
    </repository>
</repositories>
like image 945
Assen Kolov Avatar asked May 24 '16 13:05

Assen Kolov


3 Answers

You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with the Maven Repository Manager to proxy external requests.

To achieve this, set mirrorOf to *.

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

more details here

hope this helps.

like image 163
Hisham Khalil Avatar answered Sep 23 '22 00:09

Hisham Khalil


If you look at the log information, you will see that it did not download multiple times.

[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)

[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)

As you can see, their paths are different, even if the jar files are same and at the end of the second INFO, it says 0 B at 0.0 KB/sec that means, it was not downloaded.

like image 40
drJava Avatar answered Sep 20 '22 00:09

drJava


It's not downloading it multiple times. It's not able to find it in the first repository, so it's trying the next one on your <repositories/> list.

like image 44
carlspring Avatar answered Sep 22 '22 00:09

carlspring