简体   繁体   English

无法创建自定义BOM。 由于无法解析的导入POM,项目构建失败:找不到工件

[英]Cannot create custom BOM. Project build fails with Non-resolvable import POM: Could not find artifact

I am using eclipse mars with embedded maven (version 3.3.9) and i am facing a problem i cannot understand in order to resolve it. 我正在使用带有嵌入式Maven(版本3.3.9)的Eclipse火星,并且遇到了无法解决的问题。 I have been trying to create a JMS related "library" that some other projects can use in their pom under their dependencyManagement section (in other words following the "BOM" pattern). 我一直在尝试创建一个与JMS相关的“库”,其他项目可以在它们的pom中的“ dependencyManagement”部分下使用它们(换句话说,遵循“ BOM”模式)。 However, when the created BOM is pulled in the dependencyManagement section of the corresponding project that is supposed to use it, the dependencies specified are pulled in, but the project build itself ( mvn clean install ) fails with an error shown further down. 但是,当在应该使用它的相应项目的dependencyManagement部分中提取创建的BOM时,指定的依赖项将被导入,但是项目构建本身( mvn clean install )失败,并进一步显示错误。

The structure i used is the following: 我使用的结构如下:

A " jms-dependencies-BOM " project (packaged as pom), which includes as a submodule a " jms-dependencies-parent " project (again packaged as pom) which in turn inherits from the " jms-dependencies-BOM " project. 一个“ jms-dependencies-BOM ”项目(打包为pom),其中包括一个“ jms-dependencies-parent ”项目(再次打包为pom)作为子模块,该项目又继承了“ jms-dependencies-BOM ”项目。 Additionally, there is a " amqdeps " submodule of the aforementioned " jms-dependencies-parent " project (packaged as a jar). 此外,上述“ jms-dependencies-parent ”项目(打包为jar)有一个“ amqdeps ”子模块。 The " amqdeps " submodule also inherits from the " jms-dependencies-parent " project. amqdeps ”子模块还继承自“ jms-dependencies-parent ”项目。 The corresponding project that is supposed to import the " jms-dependencies-BOM " pom in its dependencyManagement section and use the " amqdeps " dependency in the dependencies section is " TestIntegrator ". 应该在“ dependencyManagement ”部分中导入“ jms-dependencies-BOM ” pom并在“ dependencies ”部分中使用“ amqdeps ”依赖项的相应项目是“ TestIntegrator ”。

Although it does sound like a duplicate i am not sure it is. 虽然听起来像是重复的,但我不确定。 My error message is a bit different (no mention of an incorrect relative path for example as in other questions).Now i have tried everything i could think of, purging the whole .m2/repository folder, tried to build the TestIntegrator project from the cli using even a slightly different maven version (3.2) than the embedded one in eclipse. 我的错误消息有些不同(例如,在其他问题中没有提及不正确的相对路径)。现在,我已经尝试了所有可能想到的方法,清除了整个.m2 / repository文件夹,尝试从中构建TestIntegrator项目。 cli使用的Maven版本(3.2)与Eclipse中的嵌入式版本略有不同。 Basically i have tried everything suggested by similar questions asked,all to the same result. 基本上,我已经尝试过由类似问题提出的所有建议,所有这些都得到相同的结果。 I suppose it is something with the way i have structured the BOM hierarchy of the projects (the relative paths perhaps, although the compiler does not complain about it) but i do not understand it enough. 我想这与我构造项目的BOM层次结构的方式有关(也许是相对路径,尽管编译器没有抱怨),但我对此并不了解。

" jms-dependencies-BOM " pom 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>

The " jms-dependencies-parent " pom 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>

The " amqdeps " pom amqdeps绒球

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

and finally the " TestIntegrator " pom 最后是“ 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>

When i do a mvn clean install in the parent project (ie " jms-dependencies-BOM ") everything is build and i can see the corresponding poms for the " jms-dependencies-BOM ", " jms-dependencies-parent " and " amqdeps " (and the jar for the amqdeps project as well) being installed in the corresponding .m2/repository folder under directories of com/test/... . 当我在父项目中执行mvn全新安装(即“ jms-dependencies-BOM ”)时,一切都已构建,并且我可以看到“ jms-dependencies-BOM ”,“ jms-dependencies-parent ”和“ amqdeps ”(以及amqdeps项目的jar)也安装在com / test / ...目录下相应的.m2 / repository文件夹中。 In addition i can see the dependencies listed in the amqdeps project being pulled in the TestIntegrator project, with no errors showing anywhere. 此外,我可以看到amqdeps项目中列出的依赖项已在TestIntegrator项目中拉出,任何地方都没有显示错误。 However, every time i try to perform a mvn clean install from the IDE in the TestIntegrator project it fails with the following error: 但是,每次我尝试从TestIntegrator项目中的IDE执行mvn全新安装时 ,它都会失败,并显示以下错误:

[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

Can anyone help me out please? 有人可以帮我吗?

The reason for this particular error seems to be a simple typo in the version string. 出现此特定错误的原因似乎是版本字符串中的一个简单错字。 Your are trying to import 您正在尝试导入

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

while the project version is actually 而项目版本实际上是

<version>0.0.1-SNAPSHOT</version>

Note the . 注意. vs - difference. VS -差异。

That said, I do believe you should read more about Project Inheritance vs Project Aggregation and make sure you understand the details of how reactor builds work . 也就是说,我确实相信您应该阅读有关Project Inheritance vs Project Aggregation的更多信息,并确保您了解Reactor构建工作原理的详细信息。 Then perhaps you may want to re-think how you structure your modules. 然后,也许您可​​能需要重新考虑如何构造模块。 I'm not judging you (may be you have your good reasons to do what you do), but at first look it seams your multi-module structure is somewhat messy and thus fragile. 我并不是在判断您(也许您有充分的理由去做您的工作),但是乍一看它似乎使您的多模块结构有些混乱,因此很脆弱。

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

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