运行mvn依赖项时,Maven无法识别兄弟模块:tree

时间:2022-07-31 00:01:53

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

我正在尝试设置一个多模块Maven项目,并且模块间依赖关系显然没有正确设置。

I have:

我有:

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

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

在父POM(具有打包类型的pom)中,然后是子目录commons /和storage /,它们定义具有相同名称的JAR poms。

Storage depends on Commons.

存储取决于Commons。

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

在main(master)目录中,我运行mvn dependency:tree并查看:

[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

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

为什么对“公共”的依赖性失败,即使反应堆显然已经看到它,因为它成功地处理了它的依赖树?绝对不应该去'网找到它,因为它就在那里......

The pom for storage:

存储用的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>

Thanks for any suggestions!

谢谢你的任何建议!

(Edit)

(编辑)

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

为了澄清,我在这里寻找的是:我不想安装模块X来构建依赖于X的模块Y,因为两者都是从同一父POM引用的模块。这对我来说很直观,如果我在同一个源代码树中有两件事,我就不必安装中间产品来继续构建。希望我的想法在这里有所帮助......

6 个解决方案

#1


17  

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希望将它作为jar(或其他)包装并至少从本地仓库获得。我敢肯定,如果你在你的commons项目上运行mvn install,那么一切都会有效。

#2


87  

As discussed in this maven mailing list thread, the dependency:tree goal by itself will look things up in the repository rather than the reactor. You can work around this by mvn installing, as previously suggested, or doing something less onerous that invokes the reactor, such as

正如在这个maven邮件列表线程中所讨论的那样,依赖:树目标本身将在存储库而不是反应堆中查找。你可以通过mvn安装来解决这个问题,如前所述,或者做一些不那么繁琐的调用反应堆的东西,比如

mvn compile dependency:tree

Works for me.

适合我。

#3


7  

Realizing this is an older thread but it seems that either the tool evolved or this might have been missed the first time around.

意识到这是一个较旧的线程,但似乎工具进化或第一次可能已经错过了。

It is possible to perform a build that makes dependencies resolved without installing by doing a reactor build.

通过执行反应器构建,可以执行构建,从而无需安装即可解析依赖关系。

If you start your build in the parent that describes the module structure of your project then your dependencies between your modules will be resolved during the build itself through the internal Maven reactor.

如果您在描述项目模块结构的父项中开始构建,那么模块之间的依赖关系将在构建过程中通过内部Maven反应器解析。

Of course this is not the perfect solution since it does not solve the build of a single individual module within the structure. In this case Maven will not have the dependencies in his reactor and will bee looking to resolve it in the repository. So for individual builds you still have to install the dependencies first.

当然,这不是完美的解决方案,因为它无法解决结构中单个模块的构建问题。在这种情况下,Maven将不会在他的反应堆中具有依赖关系,并且希望在存储库中解决它。因此,对于单个构建,您仍然必须首先安装依赖项。

Here is some reference describing this situation.

以下是描述这种情况的一些参考。

#4


3  

for me, what led me to this thread was a similar problem and the solution was to ensure all module dependency pom's had

对我来说,是什么导致我这个线程是一个类似的问题,解决方案是确保所有模块依赖pom的

 <packaging>pom</packaging>

the parent had

父母有

pom

POM

my model dep had pom - so there was no jar to be found.

我的模型dep有pom - 所以没有找到jar。

#5


3  

The only thing that workd for me : switching to gradle :(

对我来说唯一有用的东西:切换到gradle :(

I have

我有

Parent
  +---dep1
  +---war1 (using dep1)

and I can just cd in war1 and use mvn tomcat7:run-war. I always have to install the whole project before, despite war1 references his parent and the parent references war1 and dep1 (as modules) so all dependencies should be known.

我可以在war1中使用cd并使用mvn tomcat7:run-war。我总是必须安装整个项目,尽管war1引用了他的父项,而父项引用了war1和dep1(作为模块),所以所有依赖项都应该是已知的。

I don't understand what the problem is.

我不明白问题是什么。

#6


0  

Make sure the module which is failing to get resolved, is pointing to the right parent by including the configurations in the pom file of the module.

通过将配置包含在模块的pom文件中,确保未能解析的模块指向正确的父模块。

#1


17  

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希望将它作为jar(或其他)包装并至少从本地仓库获得。我敢肯定,如果你在你的commons项目上运行mvn install,那么一切都会有效。

#2


87  

As discussed in this maven mailing list thread, the dependency:tree goal by itself will look things up in the repository rather than the reactor. You can work around this by mvn installing, as previously suggested, or doing something less onerous that invokes the reactor, such as

正如在这个maven邮件列表线程中所讨论的那样,依赖:树目标本身将在存储库而不是反应堆中查找。你可以通过mvn安装来解决这个问题,如前所述,或者做一些不那么繁琐的调用反应堆的东西,比如

mvn compile dependency:tree

Works for me.

适合我。

#3


7  

Realizing this is an older thread but it seems that either the tool evolved or this might have been missed the first time around.

意识到这是一个较旧的线程,但似乎工具进化或第一次可能已经错过了。

It is possible to perform a build that makes dependencies resolved without installing by doing a reactor build.

通过执行反应器构建,可以执行构建,从而无需安装即可解析依赖关系。

If you start your build in the parent that describes the module structure of your project then your dependencies between your modules will be resolved during the build itself through the internal Maven reactor.

如果您在描述项目模块结构的父项中开始构建,那么模块之间的依赖关系将在构建过程中通过内部Maven反应器解析。

Of course this is not the perfect solution since it does not solve the build of a single individual module within the structure. In this case Maven will not have the dependencies in his reactor and will bee looking to resolve it in the repository. So for individual builds you still have to install the dependencies first.

当然,这不是完美的解决方案,因为它无法解决结构中单个模块的构建问题。在这种情况下,Maven将不会在他的反应堆中具有依赖关系,并且希望在存储库中解决它。因此,对于单个构建,您仍然必须首先安装依赖项。

Here is some reference describing this situation.

以下是描述这种情况的一些参考。

#4


3  

for me, what led me to this thread was a similar problem and the solution was to ensure all module dependency pom's had

对我来说,是什么导致我这个线程是一个类似的问题,解决方案是确保所有模块依赖pom的

 <packaging>pom</packaging>

the parent had

父母有

pom

POM

my model dep had pom - so there was no jar to be found.

我的模型dep有pom - 所以没有找到jar。

#5


3  

The only thing that workd for me : switching to gradle :(

对我来说唯一有用的东西:切换到gradle :(

I have

我有

Parent
  +---dep1
  +---war1 (using dep1)

and I can just cd in war1 and use mvn tomcat7:run-war. I always have to install the whole project before, despite war1 references his parent and the parent references war1 and dep1 (as modules) so all dependencies should be known.

我可以在war1中使用cd并使用mvn tomcat7:run-war。我总是必须安装整个项目,尽管war1引用了他的父项,而父项引用了war1和dep1(作为模块),所以所有依赖项都应该是已知的。

I don't understand what the problem is.

我不明白问题是什么。

#6


0  

Make sure the module which is failing to get resolved, is pointing to the right parent by including the configurations in the pom file of the module.

通过将配置包含在模块的pom文件中,确保未能解析的模块指向正确的父模块。