Maven依赖解析问题

时间:2015-03-12 18:24:55

标签: android maven nexus

让我们说我有一个多模块maven项目,有3个模块:

父母A和儿童B和C

C依赖于B.

鉴于我的.m2本地存储库不包含任何工件(手动删除它们),当我在父A模块上运行构建时,maven做的第一件事就是从Nexus下载B依赖项

我想知道是否有一种方法可以阻止它,我只想让maven先构建B然后再使用那个B工件来构建C.我不希望它在B时从nexus下载它无论如何都会在这个版本中建造。

我也不想使用-o(离线)选项。我只想了解maven究竟是如何运作的。

我猜这是因为这两个B工件都有相同的快照版本?

干杯

编辑:这只发生一次,第一次运行构建时。如果我再次运行它,B已经存在于我的m2目录中,因此它不再被提取。我只是想知道为什么B第一次下载

Edit2:这是我用

构建父pom.xml的第一行示例
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

你可以看到"常见"模块罐,"普通" module test-jar和" application.apk"即使在构建公共和应用程序模块时也会创建这些工件,也会下载。

在pom.xml中,我有以下内容(仅限代码段):

父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>

常见的pom.xml:不依赖于其他模块

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>

1 个答案:

答案 0 :(得分:1)

更新误解:我删除了结构化模块在maven中如何工作的更一般的解释 - 你已经有了。

如果你的结构是这样的

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

你的模块B和C都有正确的依赖关系(可能会在你的模块中添加父&gt; relativePath)并且根pom没有依赖关系,但只有一个dependencyManagement,它不应该下载模块的工件。 / p>

尝试添加relativePath:

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

检查你的root pom.xml是否有依赖关系 - 你不应该在这里声明对你自己的模块的依赖,只有dependencyManagement。