使用pom-packaging Maven项目作为依赖项 [英] Use pom-packaging maven project as dependency

查看:620
本文介绍了使用pom-packaging Maven项目作为依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在咨询有关将pom-packaging maven项目用作另一个项目中的依赖项的问题.我尝试阅读Maven的文档并在线搜索,但是找不到解决方法.

I'm consulting a question on using pom-packaging maven project as dependency in another project. I tried reading the documentation of maven and searching online, but I found few solution.

pom-packaging项目由jar打包的多个子模块组成,类似于:

The pom-packaging project consists of multiple submodules which are jar-packaging, analogous to:

<project ...>
    <groupId>the.pom.project</groupId>
    <artifactId>pom-project</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <modules>
            <module>a-pom-module</module>
            <module>b-pom-module</module>
            <module>c-pom-module</module>
            <module>d-pom-module</module>
            <module>e-pom-module</module>
            <module>f-pom-module</module>
    </modules>
</project>

另一个项目取决于pom-project的子模块jar.我这样写:

And the other project depends on the submodule jars of pom-project. I write like:

<project ...>
    <groupId>the.another.project</groupId>
    <artifactId>another-project</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <dependencyManagement>
            <dependencies>
                    <dependency>
                            <groupId>the.pom.project</groupId>
                            <artifactId>pom-project</artifactId>
                            <version>1.0</version>
                            <type>pom</type>
                    </dependency>
            </dependencies>
    </dependencyManagement>
</project>

我试图将pom项目添加为依赖项,目的是将所有子模块jar添加到另一个项目的类路径中,但这似乎对我不起作用.

I tried to add the pom project as dependency, aiming to add all the submodule jars into the classpath of another project, but it seems not to work for me.

我不希望手动将所有子模块添加为依赖项.

推荐答案

您导入pom的方法无效.

Your way of importing the pom does not work.

您需要创建一个新的pom,以聚合所需的依赖项,然后在项目中添加对该聚合pom的依赖项

You need create new pom which aggregates the dependencies you want and then add dependency on that aggregate pom in your project

按如下所示创建聚合pom

Create aggregate pom as follows

<groupId>the.pom.project</groupId>
    <artifactId>aggregate-pom</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>the.pom.project</groupId>
            <artifactId>a-pom-module</artifactId>
            <version>1.0</version>
        </dependency>
        .
        .
        .
    <dependencies>

然后在您的项目中使用以下依赖项

Then use following dependency in you project

<dependency>
    <groupId>the.pom.project</groupId>
    <artifactId>aggregate-pom</artifactId>
    <version>1.0</version>
    <type>pom</type>
</dependency>

这篇关于使用pom-packaging Maven项目作为依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆