Maven:在没有构建该pom模块的情况下从另一个pom导入依赖项?

时间:2018-10-12 18:27:08

标签: maven dependencies pom.xml dependency-management multi-module

我有一个相当复杂的多模块项目,整个项目中都有父/子pom关系。我有一个子模块(我将其称为 C ),该子模块需要在其他模块poms中定义的依赖项才能正确构建。问题在于,我要导入的pom文件的某些模块未按构建顺序在此项目之前构建,并且导致导入对这些未构建模块的依赖项时出错。

以下是我孩子的dependencyManagement定义的一个示例:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>group-z</groupId>
            <artifactId>A</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>group-z</groupId>
            <artifactId>B</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- How to import dependencies without having duplicate entries to maintain? -->
        <!-- These dependencies can't get loaded because they aren't built yet. -->
        <dependency>
            <groupId>group-z</groupId>
            <artifactId>D</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>group-y</groupId>
            <artifactId>E</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>group-z</groupId>
            <artifactId>F</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

工件A和B在该模块之前的同一父pom下构建。在此模块之后 构建工件D,E和F,并指定不同父poms。

我想做的是从D,E和F获取依赖项,这样我就不必在C中复制它们,这将迫使我在C和中维护它们。 > D,E和F。我希望pom导入能够做到这一点,但是在项目的初始构建过程中收到以下错误:

[INFO] Scanning for projects...
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-z/D/2.1-SNAPSHOT/maven-metadata.xml
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-z/D/2.1-SNAPSHOT/D-2.1-SNAPSHOT.pom
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-y/E/2.1-SNAPSHOT/maven-metadata.xml
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-y/E/2.1-SNAPSHOT/E-2.1-SNAPSHOT.pom
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-z/F/2.1-SNAPSHOT/maven-metadata.xml
Downloading from local-repo: file:///Users/someuser/local-repo/m2_repository/group-z/F/2.1-SNAPSHOT/F-2.1-SNAPSHOT.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact group-z:D:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 37, column 25
[ERROR] Non-resolvable import POM: Could not find artifact group-y:E:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 44, column 25
[ERROR] Non-resolvable import POM: Could not find artifact group-z:F:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 51, column 25
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project group-z:C:2.1-SNAPSHOT (/Users/someuser/project/parent-1/group-z/C/pom.xml) has 3 errors
[ERROR]     Non-resolvable import POM: Could not find artifact group-z:D:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 37, column 25 -> [Help 2]
[ERROR]     Non-resolvable import POM: Could not find artifact group-y:E:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 44, column 25 -> [Help 2]
[ERROR]     Non-resolvable import POM: Could not find artifact group-z:F:pom:2.1-SNAPSHOT in local-repo (file:///Users/someuser/local-repo/m2_repository) @ line 51, column 25 -> [Help 2]
[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

您知道是否可以在不保持多个位置相同的依赖关系的情况下完成我想做的事情吗?我认为创建BOM表的父级将很困难,因为模块本身被划分为不同的父级,而这些父级都是顶级项目父级下的所有子模块。我遇到的任何文档或stackoverflow问答都没有解决这样的问题,所以我认为我应该启动自己的线程。

谢谢!

0 个答案:

没有答案