Create pom from existing multi-project build with dependencies


(Ben Middleton) #1

Hello,

A new challenge. I have a multi-project build with the following:

:project-a
dependencies {
    archives "com.mydomain:dependency-1:1.0:assembly@zip",
        "com.mydomain:dependency-2:1.0:assembly@zip"
}

:project-b
dependencies {
    archives "com.mydomain:dependency-3:1.0:assembly@zip",
        "com.mydomain:dependency-4:1.0:assembly@zip"
}

Neither of the sub-projects create any artifacts. I’m trying to create a single dependencyManagement pom from the combined set of dependencies from all the sub-projects, i.e. something like this:

<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>bom</artifactId>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.mydomain</groupId>
            <artifactId>dependency-1</artifactId>
            <version>1.0</version>
            <classifier>assembly</classifier>
            <type>zip</zip>
        </dependency>
        <dependencies>
            <groupId>com.mydomain</groupId>
            <artifactId>dependency-2</artifactId>
            <version>1.0</version>
            <classifier>assembly</classifier>
            <type>zip</zip>
        </dependency>
        <dependencies>
            <groupId>com.mydomain</groupId>
            <artifactId>dependency-3</artifactId>
            <version>1.0</version>
            <classifier>assembly</classifier>
            <type>zip</zip>
        </dependency>
        <dependencies>
            <groupId>com.mydomain</groupId>
            <artifactId>dependency-4</artifactId>
            <version>1.0</version>
            <classifier>assembly</classifier>
            <type>zip</zip>
        </dependency>
    </dependencies>
</dependencyManagement>

I originally tried using the https://github.com/spring-gradle-plugins/dependency-management-plugin plugin - but this does not support classifiers or types. So next I started to look at the maven-publish plugin - but could not get it to produce a combined set of dependencies for all the sub projects (nor indeed the dependencyManagement section).

Any ideas?

The reason for this is that I have a complex set of sub project builds, each with a different set of dependency versions. I want to be able to publish a bill of materials (bom) that a third-party can use to determine these versions, preferably without having to redefine them again.

I could just write a standalone maven pom for this - but that introduces further complexities for our build pipeline.

Thanks