繁体   English   中英

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

[英]Why does Maven not find/figure out the version of the artifact in the child pom?

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

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

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

一个名为web的库。
它取决于generalUtils库。
它有一个父,一个和一些“其他”文物。
在其中,每个“其他”工件父项是父工件,其父项是bom工件。
在父工件的DependencyManagement.Dependencies部分中,我导入generalUtils bom工件

我不必在项目web中指定任何generalUtils工件的版本。 一切顺利。

然而...

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

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

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

[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)

为什么它只是抱怨Web工件而不是关于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的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.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>

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

我想你需要的是:

父母pom:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM