android - Maven依赖解析问题

标签 android maven nexus

假设我有一个包含 3 个模块的多模块 Maven 项目:

parent A和 child B和C

C 依赖于 B。

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

我想知道是否有办法阻止它,我只想让 maven 先构建 B,然后使用那个 B Artifact 来构建 C。我不希望它在构建 B 时从 nexus 下载它无论如何在这个构建中。

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

我猜测这与两个 B Artifact 具有相同的快照版本有关吗?

干杯

编辑:这只会发生一次,即我第一次运行构建时。如果我再运行一次,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

如您所见,“通用”模块 jar、“通用”模块测试 jar 和“application.apk”已下载,即使这些 Artifact 将在构建通用和应用程序模块时创建。

在 pom.xml 中我有以下内容(只有 fragment ):

父 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:不依赖其他模块

应用程序 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>

服务器 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>

最佳答案

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

如果你的结构是这样的

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

并且你的模块 B 和 C 都有正确的依赖关系(可能添加 parent > relativePath 到你的模块)并且根 pom 没有依赖关系,只有一个 dependencyManagement,它不应该下载你的模块的 Artifact 。

尝试添加相对路径:

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

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

关于android - Maven依赖解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29017495/

相关文章:

android - 膨胀 XML android.support.v7.widget.CardView 时出错

android - 如何以编程方式更改渐变的 startColor 属性 - Android

android - 适用于 iOS/Android 的嵌入式浏览器应用程序

android - 如何在 android 中读取 .doc、.docx、.xls 文件

java - Eclipse 无法识别使用 Maven 创建的 Java Web 项目

java - 您好,我面临跨浏览器测试的问题。我没有同时启动两个浏览器

java - 如何在 Maven 构建期间重命名生成的类?

maven - 无法解析Gradle中的jar依赖项

python - Python pip的pip.conf和pypirc文件有什么区别?

maven - 如何将 Sonatype Nexus 存储库组与 Github 原始存储库结合使用?