2

I’m using Maven 3.2.3. I have this dependency in my JAR project …

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>1.6.2</version>
        <scope>provided</scope>
    </dependency>

This artifact exists in my ~/.m2/repository . However, every day when I build the project (this happens only the first time per day), Maven attempts to download the artifact again …

Downloading: https://repository-mainco.forge.cloudbees.com/release/joda-time/joda-time/maven-metadata.xml
Downloading: http://files.couchbase.com/maven2/joda-time/joda-time/maven-metadata.xml
Downloading: https://repository-mainco.forge.cloudbees.com/private/joda-time/joda-time/maven-metadata.xml
Downloading: http://download.java.net/maven/2/joda-time/joda-time/maven-metadata.xml
Downloading: https://repo.maven.apache.org/maven2/joda-time/joda-time/maven-metadata.xml
Downloaded: https://repo.maven.apache.org/maven2/joda-time/joda-time/maven-metadata.xml (931 B at 0.7 KB/sec)

And in my ~/.m2/settings.xml file I have set the updatePolciy to never …

    <repository>
      <id>cloudbees-private-release-repository</id>
      <url>https://repository-mainco.forge.cloudbees.com/release</url>
      <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
            <enabled>false</enabled>
      </snapshots>
    </repository>

so I’m not sure why Maven attempts to download this artifact that I already have. How do I make it stop (that is, only download the artifact if I don’t have it)?

Edit: I added the following to the repositories section of my ~/.m2/settings.xml file …

    <repository>
            <id>central</id>
            <url>http://download.java.net/maven/2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
    </repository>
    <repository>
            <id>central2</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
    </repository>
    <repository>
            <id>nuxeo</id>
            <url>http://maven.nuxeo.org/nexus/content/repositories/public</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
    </repository>
    <repository>
            <id>spring-repo</id>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
    </repository>

but despite this, when I run a build, the first few lines of processing yields …

Downloading: http://download.java.net/maven/2/org/mainco/subco/orders/78.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/subco/78.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/core/78.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/session/78.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/joda-time/joda-time/maven-metadata.xml
Downloading: https://repository-mainco.forge.cloudbees.com/private/joda-time/joda-time/maven-metadata.xml
Downloading: http://maven.nuxeo.org/nexus/content/repositories/public/joda-time/joda-time/maven-metadata.xml
Downloading: http://repo.spring.io/milestone/joda-time/joda-time/maven-metadata.xml
Downloading: http://files.couchbase.com/maven2/joda-time/joda-time/maven-metadata.xml
Downloaded: http://maven.nuxeo.org/nexus/content/repositories/public/joda-time/joda-time/maven-metadata.xml (942 B at 1.3 KB/sec)

So despite my specifying “never”, Maven is still ignoring it, or I still haven’t configured something correctly.

Edit 3: Per the request, here's the pom.xml file ...

<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>
    <artifactId>core</artifactId>
    <packaging>jar</packaging>
    <name>core</name>
    <parent>
        <artifactId>subco</artifactId>
        <groupId>org.mainco.subco</groupId>
        <version>78.0.0-SNAPSHOT</version>
    </parent>
    <url>http://maven.apache.org</url>

    <dependencyManagement>
        <dependencies>
            <!-- Third Party dependencies -->
            <dependency>
                <groupId>aopalliance</groupId>
                <artifactId>aopalliance</artifactId>
                <version>${version.aopalliance}</version>
            </dependency>
            <dependency>
                <groupId>taglibs</groupId>
                <artifactId>standard</artifactId>
                <version>${version.standard.taglibs}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.mainco.subco</groupId>
            <artifactId>session</artifactId>
            <version>${project.parent.version}</version>
                        <exclusions>
                                <exclusion>
                                        <groupId>junit</groupId>
                                        <artifactId>junit-dep</artifactId>
                                </exclusion>
                        </exclusions>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
            </exclusions>
                <scope>provided</scope>
            </dependency>
                <dependency>
                        <groupId>org.apache.httpcomponents</groupId>
                        <artifactId>httpclient</artifactId>
                        <version>4.3.4</version>
                </dependency>
        <!-- AWS Java SDK -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.8.5</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
                 <groupId>org.springframework.security</groupId>
                 <artifactId>spring-security-config</artifactId>
                 <scope>test</scope>
        </dependency>
    <!-- Powermock for testing statics -->
        <!-- Required for PowerMock -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
        <version>${powermock.version}</version>
            <!-- <version>1.4.12</version> -->
            <scope>test</scope>
        </dependency>
        <!-- Required for PowerMockRule -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4-rule-agent</artifactId>
        <version>${powermock.version}</version>
            <!-- <version>1.4.12</version> -->
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-easymock</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <!-- spymemcached -->
        <dependency>
            <groupId>spy</groupId>
            <artifactId>spymemcached</artifactId>
            <version>2.8.4</version>
        </dependency>
        <!-- Commons stuff -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt-springsecurity3</artifactId>
            <version>1.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt-hibernate4</artifactId>
            <version>1.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk16</artifactId>
            <version>1.46</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.9</version>
            <scope>provided</scope>
        </dependency>

        <!-- Import the JPA API using the provided scope It is included in JBoss 
            AS 7 / EAP 6 -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency> 

        <!-- JSR-303 (Bean Validation) Implementation -->
        <!-- Provides portable constraints such as @Email -->
        <!-- Hibernate Validator is shipped in JBoss AS 7 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Import Spring dependencies, these are either from community or versions 
            certified in WFK2 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>
        <!-- Other community dependencies -->
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.6.3</version>
            <scope>provided</scope>
        </dependency>
        <!-- Needed for running tests (you may also use TestNG) -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${version.junit}</version>
            <scope>test</scope>
        </dependency>

        <!-- Add cglib for the MemberDaoTest -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency> 

        <!-- Add JSON dependency, specified in jboss-deployment-structure.xml -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.3</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.3</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.directwebremoting</groupId>
            <artifactId>dwr</artifactId>
            <version>3.0.0-rc2</version>
        </dependency>
        <dependency>
            <groupId>net.jeremybrooks</groupId>
            <artifactId>knicker</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jets3t</groupId>
            <artifactId>jets3t</artifactId>
            <version>0.9.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${version.mysql}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.simpleframework</groupId>
            <artifactId>simple</artifactId>
            <version>5.0.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.owasp.esapi</groupId>
            <artifactId>esapi</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.owasp.antisamy</groupId>
            <artifactId>antisamy</artifactId>
            <version>1.5.3</version>
        </dependency>
        <!-- Joda Time, supplied by JBoss -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>1.6.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.1.7</version>
        </dependency>
    <dependency>
        <groupId>org.mainco.subco</groupId>
        <artifactId>database</artifactId>
        <version>${project.parent.version}</version>
        <scope>test</scope>
    </dependency> 
        <dependency>
            <groupId>org.subethamail</groupId>
            <artifactId>subethasmtp</artifactId>
            <version>3.1.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
Dave A
  • 2,780
  • 9
  • 41
  • 60
  • You could use the offline flag: `mvn -O` – Alexander Apr 20 '15 at 16:13
  • Are you sure joda-time is being pulled from the repository you defined and not from another (e.g. Maven central)? In the log info you provided, I don't see the `https://repository-evotext.forge.cloudbees.com/release` URL. – user944849 Apr 20 '15 at 16:28
  • Alexander, will the "-O" flag prevent downloading of artifact from remote repositories if those artifacts don't exist in my local repo? @user944849, I don't know where joda-time is being pulled from but why is it being pulled from anywhere since I already have it in my local repo? – Dave A Apr 21 '15 at 14:00
  • You are on the right track by defining the updatePolicy to "never". Trouble is, you need to configure that updatePolicy setting on any repo that you are downloading from. This is another reason to use a repository manager, then you only need to configure the policies once. See [this Stackoverflow answer](http://stackoverflow.com/a/16425036/944849) for a more detailed explanation. Also note, in this case Maven is downloading metadata, not the jar itself. It detects that your local copy of the jar is the same as the remote and doesn't download the jar again (from what I see in the post). – user944849 Apr 21 '15 at 15:44
  • Does what you're saying apply to downloading of the metadata files? You may have seen my response to the other answer. He suggested a similar thing but Maven is still attempting to download things. – Dave A Apr 22 '15 at 13:59

1 Answers1

0

use dependency:list-repositories goal to determine the repository id

mvn dependency:list-repositories

you will get something like this:

[INFO] --- maven-dependency-plugin:2.8:list-repositories (default-cli) @ hello-world ---
[INFO] Repositories Used by this build:
[INFO]       id: central
      url: https://repo.maven.apache.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => daily]

after that you can configure the appropriate repo(central in our case):

 <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>

and you will get the result:

[INFO] --- maven-dependency-plugin:2.8:list-repositories (default-cli) @ hello-world ---
[INFO] Repositories Used by this build:
[INFO]       id: central
      url: https://repo.maven.apache.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => never]
Yuri G.
  • 4,323
  • 1
  • 17
  • 32
  • Hi, I edited my question to show that I added your suggestion to my ~/.m2/settings.xml file, however Maven is still attempting to download teh artficats. – Dave A Apr 22 '15 at 13:58
  • If I understand correctly the [maven documentation](https://maven.apache.org/settings.html#Repositories), looks like the download that you see is done to compare the local pom to the remote. If this solution doesn't satisfies your requirements the only option that I can see is to use the offline mode. you can prepare your project to work offline by running `dependency:go-offline` goal – Yuri G. Apr 22 '15 at 16:26
  • If that's true, why does Maven only do that for the joda-time artifact? If it compared metadata files for every dependency in my pom, I would see a lot more download messages, wouldn't I? – Dave A Apr 22 '15 at 16:59
  • Can you share the pom file? – Yuri G. Apr 22 '15 at 17:05
  • I tried adding the pom, but SO cut off its complete inclusion. What information are you looking for in there? I included the orignal joda-time dependency at the beginning of my question. – Dave A Apr 23 '15 at 15:14
  • Just wanted to reproduce the issue on my machine. – Yuri G. Apr 23 '15 at 15:24
  • Hi, I was not able to reproduce the issue with your pom since I don't have an access to the parent, but it seems that your repository configuration is wrong. You wrote that you put it the `settings.xml` file, but according to the [Maven Settings Docs](http://maven.apache.org/settings.html#Quick_Overview) the repositories should be defined in the `settings.xml`file within a profile. did you put it within a profile? Is the profile active by default? Can you share the output of the `dependency:list-repositories` goal? – Yuri G. Apr 23 '15 at 21:29
  • 1
    Hi, Yes, teh block is in a profile taht has "true". It is most curious that only some dependencies get repeatedly downloaded (e.g. joda-time). Thanks for your help. – Dave A Apr 30 '15 at 13:45