13

I have a small problem with my Maven config. All other questions and answers here didn't solve my problem, so I'm starting a new question.

My problem is, that my Maven is not using the local repository. It's always fetching the artifacts from the remote repositories.

When an artifact is downloaded or when I build a project it is installed in the local repository, so the path is correct.

The problem is: When I build one SNAPSHOT project, it is only installed in the local repository (should be like this, don't want to publish it on my nexus every time). When I build another project having the previous one as dependency in the pom.xml maven wants to download the artifact from the nexus server where it didn't find it instead of taking it from the local repository.

This is my maven config:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <localRepository>C:\Users\Marc\.m2\repository</localRepository>
  <interactiveMode>false</interactiveMode>
  <usePluginRegistry>false</usePluginRegistry>
  <pluginGroups>
  </pluginGroups>
  <servers>
    <server>
      <id>releases</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
    <server>
      <id>snapshots</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
    <server>
      <id>nexus</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>nexussrv</id>
      <repositories>
        <repository>
          <id>snapshots</id>
          <url>http://nexus/content/repositories/snapshots</url>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
          <releases>
            <enabled>false</enabled>
          </releases>
        </repository>
        <repository>
          <id>releases</id>
          <url>http://nexus/content/repositories/releases</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>nexus</id>
          <url>http://nexus/content/groups/public</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexussrv</activeProfile>
  </activeProfiles>
</settings>

Downloading from the nexus and publishing artifacts (SNAPSHOT and RELEASE) to the nexus work with this config but it doesn't use artifacts from the local repository.

Thanks for your Help!

virtualmarc
  • 533
  • 1
  • 4
  • 16

2 Answers2

17

You've configured that the SNAPSHOTs should always (<updatePolicy>always</updatePolicy>) be downloaded from your snapshot-nexus. So even if your local cache (the ~/.m2/repository) has a newer version of the snapshot, maven tries to download it from the configured server (http://nexus/content/repositories/snapshots).

Think about changing the updatePolicy for the snapshot-entry. E.g. if you have a CI-server which deploys a SNAPSHOT daily (in the morning) to the snapshot-nexus, change the updatePolicy to daily.

MrD
  • 1,255
  • 1
  • 10
  • 24
  • 1
    mhh. I set it from always to daily but it still try's to receive it from the nexus. – virtualmarc Oct 04 '13 at 12:41
  • 4
    As mentioned, maven then checks the nexus once per day. This is only usable, if you have some snapshots there (e.g. if a CI-server deploys it). If you will never have shnapshots on the nexus, then you should set the updatePolicy to never. – MrD Oct 04 '13 at 12:44
0

If you change you'r config to <updatePolicy>always</updatePolicy>, it still will attempts to download from the nexus, because you have to disable nexus config in pom.xml
mind that <reposotiry> tag in your pom.xml will take precedence over what's defined in your settings.xml

Tohid Makari
  • 1,700
  • 3
  • 15
  • 29