【问题标题】:Cannot create custom BOM. Project build fails with Non-resolvable import POM: Could not find artifact无法创建自定义 BOM。项目构建失败并出现不可解析的导入 POM:找不到工件
【发布时间】:2020-01-15 02:32:46
【问题描述】:

我正在使用带有嵌入式 maven(版本 3.3.9)的 eclipse mars,我遇到了一个我无法理解的问题以解决它。我一直在尝试创建一个与 JMS 相关的“库”,其他一些项目可以在他们的 pom 中使用它们的 dependencyManagement 部分(换句话说,遵循“BOM”模式)。但是,当创建的 BOM 被拉入应该使用它的相应项目的 dependencyManagement 部分时,指定的依赖项被拉入,但项目构建本身 (mvn clean install) 失败并显示错误显示在下面。

我使用的结构如下:

一个“jms-dependencies-BOM”项目(打包为 pom),它作为子模块包含一个“jms-dependencies-parent”项目(再次打包为pom) 继承自 "jms-dependencies-BOM" 项目。此外,上述“jms-dependencies-parent”项目(打包为jar)还有一个“amqdeps”子模块。 “amqdeps”子模块也继承自“jms-dependencies-parent”项目。应该在其dependencyManagement部分中导入“jms-dependencies-BOM”pom并在dependencies部分中使用“amqdeps”依赖项的相应项目是“TestIntegrator”。

虽然听起来确实像重复,但我不确定是不是。我的错误信息有点不同(没有提到不正确的相对路径,例如在其他问题中)。现在我已经尝试了我能想到的一切,清除整个 .m2/repository 文件夹,试过了从 cli 构建 TestIntegrator 项目,甚至使用与 eclipse 中的嵌入式版本略有不同的 maven 版本 (3.2)。基本上我已经尝试了类似问题提出的所有建议,所有结果都相同。我想这与我构建项目的 BOM 层次结构的方式有关(也许是相对路径,尽管编译器没有抱怨它),但我对它的理解还不够。

"jms-dependencies-BOM" pom

<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.test</groupId>
  <artifactId>jms-dependencies-BOM</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <amqdeps.version>0.0.1-SNAPSHOT</amqdeps.version>
  </properties>

  <dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>com.test</groupId>
            <artifactId>amqdeps</artifactId>
            <version>${amqdeps.version}</version>
        </dependency>

    </dependencies>  
  </dependencyManagement>

  <modules>
    <module>jms-dependencies-parent</module>
  </modules>
</project>

jms-dependencies-parent”pom

<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>
  <parent>
    <groupId>com.test</groupId>
    <artifactId>jms-dependencies-BOM</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>
  <groupId>com.test</groupId>
  <artifactId>jms-dependencies-parent</artifactId>
  <packaging>pom</packaging>

  <properties>
    <activemq.version>5.13.1</activemq.version>
  </properties>

  <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-client</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-openwire-legacy</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-jaas</artifactId>
            <version>${activemq.version}</version>
        </dependency>

        <--MORE DEPENDENCIES TRUNCATED FOR CLARITY-->

    </dependencies>
  </dependencyManagement>

  <modules>
    <module>amqdeps</module>
  </modules>
</project>

amqdeps”pom

<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>
  <parent>
    <groupId>com.test</groupId>
    <artifactId>jms-dependencies-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>
  <artifactId>amqdeps</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-openwire-legacy</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-camel</artifactId>
    </dependency>

    <--MORE DEPENDENCIES TRUNCATED FOR CLARITY-->

  </dependencies>

  <build>
   <plugins>    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
        </plugin>

        <plugin>
             <artifactId>maven-install-plugin</artifactId>
             <version>2.5.2</version>
        </plugin>       
    </plugins>
 </build>
</project>

最后是“TestIntegrator”pom

<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.test</groupId>
  <artifactId>TestIntegrator</artifactId>
  <version>0.0.1-SNAPSHOT</version>

 <properties>
    <spring.framework.version>5.1.4.RELEASE</spring.framework.version>
    <jms-dependencies-BOM.version>0.0.1.SNAPSHOT</jms-dependencies-BOM.version>
</properties>

<dependencyManagement>  
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>${spring.framework.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>com.test</groupId>
            <artifactId>jms-dependencies-BOM</artifactId>
            <version>${jms-dependencies-BOM.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

 <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>     
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
    </dependency>

    <dependency>
        <groupId>com.test</groupId>
        <artifactId>amqdeps</artifactId>        
    </dependency>

</dependencies>

 <build>
   <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

    <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
        </plugin>

        <plugin>
             <artifactId>maven-install-plugin</artifactId>
             <version>2.5.2</version>
        </plugin>

    </plugins>
 </build>
</project>

当我在父项目(即“jms-dependencies-BOM”)中执行 mvn clean install 时,一切都已构建,我可以看到“jms-dependencies”的相应 pom -BOM", “jms-dependencies-parent”和“amqdeps”(以及 amqdeps 项目的 jar)安装在 com/test/... 。此外,我可以看到 amqdeps 项目中列出的依赖项被拉入 TestIntegrator 项目,没有任何错误显示。但是,每次我尝试从 TestIntegrator 项目中的 IDE 执行 mvn clean install 时,它都会失败并出现以下错误:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact com.test:jms-dependencies-BOM:pom:0.0.1.SNAPSHOT @ line 43, column 16
[ERROR] 'dependencies.dependency.version' for com.test:amqdeps:jar is missing. @ line 104, column 14
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.test:IgniteIntegrator:0.0.1-SNAPSHOT (C:\Users\matrix\eclipse-mars\workspace\TestIntegrator\pom.xml) has 2 errors
[ERROR]     Non-resolvable import POM: Could not find artifact com.test:jms-dependencies-BOM:pom:0.0.1.SNAPSHOT @ line 43, column 16 -> [Help 2]
[ERROR]     'dependencies.dependency.version' for com.test:amqdeps:jar is missing. @ line 104, column 14
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

谁能帮帮我?

【问题讨论】:

    标签: java eclipse maven m2eclipse parent-pom


    【解决方案1】:

    这个特定错误的原因似乎是版本字符串中的一个简单的错字。您正在尝试导入

    <jms-dependencies-BOM.version>0.0.1.SNAPSHOT</jms-dependencies-BOM.version>
    

    而项目版本实际上是

    <version>0.0.1-SNAPSHOT</version>
    

    注意 .- 的区别。

    也就是说,我相信您应该阅读更多关于 Project InheritanceProject Aggregation 的信息,并确保您了解 how reactor builds work 的详细信息。那么也许您可能想重新考虑如何构建模块。我不是在评判你(也许你有充分的理由去做你所做的事情),但乍一看,你的多模块结构有些混乱,因此很脆弱。

    【讨论】:

    • +1000 用于发现多余的点,我只是看不到!!!!非常感谢,我开始发疯了。
    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 2017-12-02
    • 2019-03-31
    • 2020-03-20
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多