为什么Maven找不到/弄清楚孩子pom中神器的版本?

时间:2017-01-24 15:26:51

标签: java maven

我正在重组一个项目并想知道为什么我需要在孩子应该知道的时候指定工件的版本......

在进入细节之前,请先概述一下 我有以下内容:

一个名为generalUtils的库 它有一个父母,一个和一些其他的'文物。
在其中,每个'其他'工件parent是父工件,其父项是bom工件

一个名为web的图书馆 这取决于generalUtils库 它有一个父母,一个孩子和一些其他的'文物。
在其中,每个'其他' artifacts parent是父工件,其父项是bom工件 在父工件的DependencyManagement.Dependencies部分中,我导入generalUtils bom工件

我不必在项目网站中指定任何generalUtils工件的版本。一切都很好。

...然而

我还有一个名为monitor的库 它取决于generalUtils和web库 它有一个父母,一个孩子和一些其他的'文物。
在其中,每个'其他' artifacts parent是父工件,其父项是bom工件 在父工件的DependencyManagement.Dependencies部分中,我导入了generalUtils和web bom工件。

我不必在任何项目监视器工件中指定任何generalUtils工件的版本。但是,如果我没有指定任何Web项目工件的版本。我收到一条错误消息。

webApi是网络库项目中的工件之一,我收到此错误消息:

[INFO] Scanning for projects...
[ERROR] The build could not read 2 projects -> [Help 1]
[ERROR]
[ERROR]   The project com.retx.monitor:eventCollector:1.0.6.InSync (C:\TFSROOT\Monitor_1.0.6.In\EventCollector\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for com.retx.web:webAPI:jar is missing. @ line 74, column 15
[ERROR]
[ERROR]   The project com.retx.monitor:eventNotifier:1.0.6.In (C:\TFSROOT\Monitor_1.0.6.In\EventNotifier\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for com.retx.web:webAPI:jar is missing. @ line 78, column 15
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
...

它抱怨其他两个'监视器项目中的工件(eventCollector和eventNotifier)我没有为Web库工件(webAPI)指定版本

为什么它只抱怨网络工件而不是关于generalUtils工件,即使它们以完全相同的方式导入?

我使用maven 2.0.11 for generalUtils和web库,但监控库是使用maven 3.0.3构建的。

现在是实际的pom文件:

项目库generalUtils bom artifact的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.retx.general.utils</groupId>
  <artifactId>bom</artifactId>
  <version>1.0.3-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>bom</name>
  <description>Bill of Materials for general utils</description>

    <properties>
        <generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version>

        <!-- wildfly third-party dependencies versions -->
    </properties>
  <dependencyManagement>
    <dependencies>
            <dependency>
                <groupId>com.retx.general.utils</groupId>
                <artifactId>configuration</artifactId>
                <version>${generalUtils.version}</version>
            </dependency>

            <!-- a few others similar to the above -->

    </dependencies>
  </dependencyManagement>       
</project>

项目库web bom artifact&#poms.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.retx.web</groupId>
  <artifactId>bom</artifactId>
  <version>3.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>bom</name>
  <description>Bill of Materials for Web</description>

    <properties>
        <webRoot.version>3.0.0-SNAPSHOT</webRoot.version>

        <!-- bring in needed boms from other streams -->
        <generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version>
    </properties>

  <dependencyManagement>
    <dependencies>
            <dependency>
                <groupId>com.retx.web</groupId>
                <artifactId>webApi</artifactId>
                <version>${webRoot.version}</version>
            </dependency>

            <!-- a few others similar to the above -->

    </dependencies>
  </dependencyManagement>
</project>

最后是监视库工件,从父级下来......

监控库bom artifact pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.retx.monitor</groupId>
  <artifactId>bom</artifactId>
  <version>1.0.6.In</version>
  <packaging>pom</packaging>
  <name>bom</name>
  <description>Bill of Materials for Monitor Modules</description>

    <properties>
        <!-- this stream -->
        <monitor.version>1.0.6.In</monitor.version>

        <!-- bring in needed boms from other streams -->
        <webRoot.version>3.0.0-SNAPSHOT</webRoot.version>           <!--  wildfly changed from 2.7.0.1-SNAPSHOT -->    
        <generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version> <!-- wildfly changed from 1.0.2-SNAPSHOT -->

        <!-- wildfly third-party dependencies versions -->
        <!-- ... -->
    </properties>

  <dependencyManagement>
    <dependencies>
            <dependency>
                <groupId>com.retx.monitor</groupId>
                <artifactId>eventCollector</artifactId>
                <version>${monitorRoot.version}</version>
                <type>ejb</type>
            </dependency>

            <dependency>
                <groupId>com.retx.monitor</groupId>
                <artifactId>eventNotifier</artifactId>
                <version>${monitorRoot.version}</version>
                <type>ejb</type>
            </dependency>
    </dependencies>
  </dependencyManagement>
</project>

监控库父工件pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns              = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi          = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
                               http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.retx.monitor</groupId>
        <artifactId>bom</artifactId>
        <version>1.0.6.In</version>
        <relativePath>bom/pom.xml</relativePath>
    </parent>

    <artifactId>monitor-root</artifactId>
    <packaging>pom</packaging>
    <name>monitor-root</name>
    <description>Monitor Modules</description>

    <dependencyManagement>
        <dependencies>
            <!-- import the generalUtils library bom -->
            <dependency>
                <groupId>com.retx.general.utils</groupId>
                <artifactId>bom</artifactId>
                <version>${generalUtils.version}</version>
                <type>pom</type>
                <scope>import</scope>   
            </dependency>

            <!-- import the web library pom -->
            <dependency>
                <groupId>com.retx.web</groupId>
                <artifactId>bom</artifactId>
                <version>${webRoot.version}</version>
                <type>pom</type>
                <scope>import</scope>   
            </dependency>

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

            <!-- other third part dependencies ->

        </dependencies>
    </dependencyManagement>

    <!-- the rest is not relevant ->
</project>

监视器库中eventCollector工件的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                               http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.retx.monitor</groupId>
        <artifactId>monitor-root</artifactId>
        <version>1.0.6.In</version>
        <relativePath>..</relativePath>
    </parent>

    <groupId>com.retx.monitor</groupId>
    <artifactId>eventCollector</artifactId>
    <packaging>ejb</packaging>
    <name>EventCollector</name>

    <dependencies>

        <!-- dependency from the generalUtils library ->
        <dependency>
            <groupId>com.retx.general.utils</groupId>
            <artifactId>utils</artifactId>
        </dependency>

        <!-- dependency from the web library ->
        <dependency>
            <groupId>com.retx.web</groupId>
            <artifactId>webAPI</artifactId>
        </dependency>

        <!-- third party artifacts-->
        <dependency>
            <groupId>org.jboss.spec.javax.jms</groupId>
            <artifactId>jboss-jms-api_2.0_spec</artifactId>
        </dependency>

        <!-- other third party artifacts-->

    </dependencies>

    <!-- the rest is not important --> 
</project>

如果我只是将版本添加到上述xml中的webApi依赖项,相关的错误消息就会消失,如:

        <!-- dependency from the web library ->
        <dependency>
            <groupId>com.retx.web</groupId>
            <artifactId>webAPI</artifactId>
            <version>${webRoot.version}</version>
        </dependency>

难道不能从父工件中的信息中推断出webAPI的版本吗?
(请注意,generalUtils依赖项不需要在此处指定版本...)

1 个答案:

答案 0 :(得分:0)

我认为你需要的是:

父母:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.greg</groupId>
  <artifactId>ear-example</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>ear-example</name>
  <modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
  </modules>

  <dependencyManagement>
     <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
      </dependency>
     </dependencies>
  </dependencyManagement>

</project>

然后在每个子/模块中,您都有一个没有版本的依赖项,即该版本是从父项继承的:

<?xml version="1.0"?>
<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>
  <parent>
    <groupId>com.greg</groupId>
    <artifactId>ear-example</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>module1</artifactId>
  <packaging>war</packaging>
  <name>example-war Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>example-war</finalName>
  </build>
</project>