Maven 在运行 mvn dependency:tree 时无法识别兄弟模块 [英] Maven doesn't recognize sibling modules when running mvn dependency:tree

查看:40
本文介绍了Maven 在运行 mvn dependency:tree 时无法识别兄弟模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个多模块 Maven 项目,但显然没有正确设置模块间依赖项.

I'm trying to set up a multi-module Maven project, and the inter-module dependencies are apparently not being set up correctly.

我有:

<modules>
  <module>commons</module>
  <module>storage</module>
</modules>

在父 POM 中(它有一个包装类型的 pom)然后是子目录 commons/storage/,它们定义了同名的 JAR poms.

in the parent POM (which has a packaging-type pom) and then subdirectories commons/ and storage/ which define JAR poms with the same name.

存储取决于共享资源.

在主(主)目录中,我运行 mvn dependency:tree 并看到:

In the main (master) directory, I run mvn dependency:tree and see:

[INFO] Building system
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] domain:system:pom:1.0-SNAPSHOT
[INFO] - junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] Building commons
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
...correct tree...
[INFO] ------------------------------------------------------------------------
[INFO] Building storage
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
Downloading: http://my.repo/artifactory/repo/domain/commons/1.0-SNAPSHOT/commons-1.0-SNAPSHOT.jar
[INFO] Unable to find resource 'domain:commons:jar:1.0-SNAPSHOT' in repository my.repo (http://my.repo/artifactory/repo)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) domain:commons:jar:1.0-SNAPSHOT

为什么对commons"的依赖会失败,即使reactor显然已经看到它,因为它成功地处理了它的依赖树?它绝对不应该去'网上找到它,因为它就在那里......

Why does the dependency on "commons" fail, even though the reactor has obviously seen it because it successfully processes its dependency tree? It should definitely not be going to the 'net to find it as it's right there...

用于存储的 pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>
  <parent>
    <artifactId>system</artifactId>
    <groupId>domain</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>domain</groupId>
  <artifactId>storage</artifactId>
  <name>storage</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <!-- module dependencies -->
    <dependency>
      <groupId>domain</groupId>
      <artifactId>commons</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <!-- other dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

感谢您的任何建议!

(编辑)

澄清一下,我在这里寻找的是:我不想安装模块 X 来构建依赖于 X 的模块 Y,因为它们都是从同一个父 POM 引用的模块.这对我来说很直观,如果我在同一个源代码树中有两个东西,我不应该安装中间产品来继续构建.希望我的想法在这里有意义...

To clarify, what I am looking for here is this: I don't want to have to install module X to build module Y which depends on X, given that both are modules referenced from the same parent POM. This makes intuitive sense to me that if I have two things in the same source tree, I shouldn't have to install intermediate products to continue the build. Hopefully my thinking makes some sense here...

推荐答案

我认为问题在于,当您指定依赖项时,Maven 希望将它打包为 jar(或其他),并且至少可以从本地存储库中获取.我敢肯定,如果您首先在您的公共项目上运行 mvn install,一切都会正常进行.

I think the problem is that when you specify a dependency Maven expects to have it as jar (or whatever) packaged and available from at least a local repo. I'm sure that if you run mvn install on your commons project first everything will work.

这篇关于Maven 在运行 mvn dependency:tree 时无法识别兄弟模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆