1

let's say I have a multi module maven project, with 3 modules:

Parent A and children B and C

C has a dependency on B.

Given that my .m2 local repository doesn't contain any of my artifacts (deleted them manually), when I run a build on the parent A module, the first thing maven does is to download the B dependency from Nexus.

I am wondering if there's a way to stop that, I only want maven to build B first and then use that B artifact for building C. I don't want it to download it from nexus when B is going to be built anyway in this very build.

I also don't want to use the -o (offline) option. I am just trying to understand how maven exactly works.

I am guessing that this is related to the fact that both B artifacts have the same snapshot version?

Cheers

Edit: This only happens once, the first time I run a build. If I run it one more time, B already exists in my m2 directory so it's not fetched again. I am just wondering why B is downloaded the very first time

Edit2: This is an example of the first lines of me building the parent pom.xml with

mvn clean install -DskipTests


[INFO] Scanning for projects...
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations/3.3-SNAPSHOT/maven-metadata.xml
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations/3.3-SNAPSHOT/maven-metadata.xml (2 KB at 2.5 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations-parent/3.3-SNAPSHOT/maven-metadata.xml
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations-parent/3.3-SNAPSHOT/maven-metadata.xml (622 B at 1.7 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations-api/3.3-SNAPSHOT/maven-metadata.xml
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/org/androidannotations/androidannotations-api/3.3-SNAPSHOT/maven-metadata.xml (2 KB at 4.2 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/maven-metadata.xml
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/maven-metadata.xml (972 B at 2.6 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/common-0.2-20150312.211752-3.jar
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/common-0.2-20150312.211752-3-tests.jar
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/common-0.2-20150312.211752-3-tests.jar (49 KB at 31.3 KB/sec)
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/common/0.2-SNAPSHOT/common-0.2-20150312.211752-3.jar (94 KB at 33.9 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/application/0.2-SNAPSHOT/maven-metadata.xml
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/application/0.2-SNAPSHOT/maven-metadata.xml (938 B at 3.2 KB/sec)
Downloading: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/application/0.2-SNAPSHOT/application-0.2-20150312.203520-2.apk
Downloaded: http://xx.xx.xx:xxxxx/nexus/content/groups/public/com/follower/application/0.2-SNAPSHOT/application-0.2-20150312.203520-2.apk (6585 KB at 63.0 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Follower
[INFO] Follower - Common
[INFO] Follower - Application
[INFO] Follower - Application Espresso Tests
[INFO] Follower - Server
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Follower 0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ follower ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ follower ---
[INFO] Installing C:\Users\sakis\Desktop\intelliJ projects\follower\pom.xml to C:\Users\sakis\.m2\repository\com\follower\follower\0.2-SNAPSHOT\follower-0.2-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Follower - Common 0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ common ---
[INFO] Deleting C:\Users\sakis\Desktop\intelliJ projects\follower\common\target
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\sakis\Desktop\intelliJ projects\follower\common\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 50 source files to C:\Users\sakis\Desktop\intelliJ projects\follower\common\target\classes

As you can see the "common" module jar, "common" module test-jar and "application.apk" is downloaded, even though these artifacts will get created when the common and application modules are built.

In the pom.xml I have the following (only snippets):

parent pom.xml:

<groupId>com.follower</groupId>
<artifactId>follower</artifactId>
<version>0.2-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>common</module>
    <module>application</module>
    <module>espresso</module>
    <module>server</module>
</modules>

common pom.xml: no dependency on other modules

application pom.xml:

<parent>
    <groupId>com.follower</groupId>
    <artifactId>follower</artifactId>
    <version>0.2-SNAPSHOT</version>
</parent>

<artifactId>application</artifactId>
<packaging>apk</packaging>

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>common</artifactId>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>common</artifactId>
        <scope>test</scope>
        <type>test-jar</type>
    </dependency>
</dependencies>

server pom.xml:

  <parent>
        <groupId>com.follower</groupId>
        <artifactId>follower</artifactId>
        <version>0.2-SNAPSHOT</version>
    </parent>

    <artifactId>server</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>common</artifactId>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>common</artifactId>
            <type>test-jar</type>
        </dependency>
    </dependencies>

espresso pom.xml:

<parent>
    <groupId>com.follower</groupId>
    <artifactId>follower</artifactId>
    <version>0.2-SNAPSHOT</version>
</parent>

<artifactId>espresso</artifactId>
<packaging>apk</packaging>

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>application</artifactId>
        <scope>provided</scope>
        <type>apk</type>
    </dependency>
</dependencies>
sakis kaliakoudas
  • 2,039
  • 4
  • 31
  • 51
  • have you tried using an older maven version? I'm using an older maven version (maven 3.2.5) and I've never come across a problem like this. BTW: it should not be because you're using the *same* snapshot version, because SNAPSHOT means "in development" and this means that maven will more likely build than download it. Did you specify a maven snapshot policy? See http://stackoverflow.com/a/3805559/2987273 and http://maven.apache.org/pom.html#Repositories – Alexander Mar 12 '15 at 21:35
  • I was using maven 3.2.1, I just tried 3.2.5 and I see exactly the same thing happening – sakis kaliakoudas Mar 12 '15 at 21:41
  • what about a snapshot policy? – Alexander Mar 12 '15 at 21:43
  • used to be the default (daily), but I also tried always. Currently it's set on always. Both same results. You mean updatePolicy right ? – sakis kaliakoudas Mar 12 '15 at 21:45
  • yeah, updatePolicy. Have you tried `never`? – Alexander Mar 12 '15 at 21:49
  • Just did and it still downloaded them.. I am wondering if I am placing the updatePolicy in the correct place.. It's in the settings.xml: nexus central http://repo1.maven.org/maven2/ true never – sakis kaliakoudas Mar 12 '15 at 22:03
  • No, it belongs to the root pom – Alexander Mar 13 '15 at 07:59

1 Answers1

1

Update misunderstanding: I removed the more general explanation how structured modules work in maven - you already have that.

If your structure is like this

A (root - no dependencies)
 - B (standalone)
 - C (dependent on B)

And you modules B and C both have a correct dependencies (maybe add parent > relativePath to your modules) and the root pom does not have dependecies, but only a dependencyManagement, it should not download the artifacts of your modules.

Try adding the relativePath:

    <parent>
        <groupId>[...]</groupId>
        <artifactId>[...]</artifactId>
        <version>0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

Check if your root pom.xml has dependencies - you should not declare dependencies to your own modules here, only dependencyManagement.

Alexander
  • 2,925
  • 3
  • 33
  • 36
  • Sorry I may not have made this clear. I do have a root pom, usually called parent pom.xml and it has the structure that you mentioned. So when I build that parent pom.xml I get the problem described: First dependency B is fetched from nexus ( can't understand why), then B is built as it's needed for C, then C is built using the B. – sakis kaliakoudas Mar 12 '15 at 20:32
  • This only happens once, the first time I run a build. If I run it one more time, B already exists in my m2 directory so it's not fetched again. I am just wondering why B is downloaded the very first time – sakis kaliakoudas Mar 12 '15 at 20:33
  • 1
    This should not happen. Can you show me the maven output and maybe you poms? It should show the reactor order. E.g. delete module B from your .m2/repository, so it has to be build / downloaded again. – Alexander Mar 12 '15 at 20:57
  • 1
    These dependencies are downloaded before the reactor, my project is a bit more complex than the example I am describing in my question, too long to type in here. I'll edit my original question – sakis kaliakoudas Mar 12 '15 at 21:22
  • Thanks for the reploy. I kinda gave up on this. I do not have any dependencies in the parent pom.xml and I do not want to have relative paths (i didn't even try to see if it solves the problem). Thanks for the effort pal – sakis kaliakoudas Mar 20 '15 at 23:31