12

I've got a multi-module project with layout as below:

pom.xml
projA
  trunk
    pom.xml
    projA1
      pom.xml
    projA2
      pom.xml

In the parent's pom I've defined dependencyManagement and properties:

<properties>
  <javaee-api.version>6.0</javaee-api.version>
  <log4j.version>1.2.11</log4j.version>
</properties>
...
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>  
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
    </dependency>
    <dependency>
      <groupId>javax</groupId>  
      <artifactId>javaee-api</artifactId>
      <version>${javaee-api.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

pom.xml for projA2 contains:

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
</dependency>

pom.xml for projA1 contains:

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>projA2</artifactId>
  <version>${project.version}</version>
</dependency>

In projA1 I'm using log4j but the dependency is transitive (from projA2).

Now when I run mvn dependency:tree -X I get:

[WARNING] Invalid POM for mypackage:projA2:jar:1.0, transitive dependencies (if any) will not be available, enable debug logging for more details: Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for javax:javaee-api:jar is missing. @ line 37, column 15
[ERROR] 'dependencies.dependency.version' for log4j:log4j:jar is missing. @ line 56, column 15

but just below this lines I get:

[DEBUG]   testArtifact: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   includeArtifact: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   startProcessChildren: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   endProcessChildren: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   testArtifact: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   includeArtifact: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   startProcessChildren: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   endProcessChildren: artifact=javax:javaee-api:jar:6.0:provided

The only solution is to specify log4j version (<version>${project.version}</version>) in projA2 pom.xml.

Question: what am I doing wrong :-(? I don't want to specify versions that are already defined in parent's dependencyManagement section.

4

7 回答 7

8

我遇到了同样的问题。在我的情况下,如果忘记更新本地存储库中的父 POM。试着做

mvn install

对于父模块。

于 2013-06-25T23:26:20.777 回答
3

有类似的问题。从本地存储库中删除(手动)所有涉及的项目并稍后运行“mvn clean install”对我有用。

于 2013-09-17T15:50:23.573 回答
0

我有一个类似的问题:我在我的 settings.xml 中定义了一个属性,并将它用于我的 pom 和我的父 pom 的依赖项中的 systemPaths。忽略“无效”包会导致编译错误,因为在类路径中缺少用作传递依赖项的包。

我发现(转移到你的问题),如果我用“mvn -Dlog4j.version=2.1.11”调用 maven,警告就会消失,编译错误也会消失。对我来说,这不是令人满意的解决方案,但它解决了隐形传递依赖的问题。

于 2014-04-15T20:07:43.803 回答
0
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
</dependency>

需要 in/projA/trunk/pom.xml而不是/projA/trunk/projA2/pom.xml.

当然,如果您希望它在您的所有项目中都可用,而不仅仅是 projA,它必须在pom.xml.

于 2013-02-08T20:12:16.130 回答
0

我遇到了与 OP 完全相同的问题。事实证明这是一个 maven 错误,因为更新到最新的 maven 版本(写作时为 3.3.3)解决了这个问题。

于 2015-10-05T08:38:32.723 回答
0

它可能是存储库问题搜索您丢失的依赖项找出正确的存储库并像这样添加到您的 pom:

<repositories>
        <repository>
            <id>jboss-3rd-party-releases</id>
            <url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/</url>
        </repository>
    </repositories>
于 2016-10-28T12:16:42.003 回答
-1

添加:

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>${log4j.version}</version>
</dependency>

dependencyManagement父 POM 的部分(就像你对 JUnit 所做的那样)。任何需要 log4j 的孩子都可以指定一个依赖项:

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
</dependency>

没有版本,它会工作,因为版本将从父级中提取。

于 2013-02-11T18:37:08.720 回答