Use pom-packaging maven project as dependency
Asked Answered
O

1

6

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.

Orthorhombic answered 13/10, 2016 at 23:37 Comment(0)
R
5

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>
Rolf answered 14/10, 2016 at 0:44 Comment(2)
Thanks, this works. Though I think there should be some plugin to automatically generate such aggregate pom while deploying.Orthorhombic
Yes there should should have been a flag for generating aggregate pomRolf

© 2022 - 2024 — McMap. All rights reserved.