Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use pom-packaging maven project as dependency

Tags:

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.

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>

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>

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.

I don't hope to add all the submodules as dependences manually.

like image 404
Haoran.Luo Avatar asked Oct 13 '16 23:10

Haoran.Luo


1 Answers

Your way of importing the pom does not work.

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

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>
like image 128
ravthiru Avatar answered Sep 25 '22 16:09

ravthiru