Skip to content

Broken maven sub-project definition

The current sub-project Maven uses:

    <parent>
        <groupId>eu.gaiax.difs.fc</groupId>
        <artifactId>fc-service</artifactId>
        <version>${revision}</version>
    </parent>

    <artifactId>fc-service-server</artifactId>
    <version>${revision}</version>

with ${revision} defined in the parent pom.

This setup is fundamentally broken. For a project to know the parent, it needs ${revision}, but to find ${revision} it needs the parent, but to find the parent it needs ${revision}, but to find ${revision} it needs the parent...

This means that many Maven features don't work, like building a single sub-project:

.../fc-service/fc-service-server $ mvn install
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< eu.gaiax.difs.fc:fc-service-server >-----------------
[INFO] Building fc-service-server 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/eu/gaiax/difs/fc/fc-service/$%7Brevision%7D/fc-service-$%7Brevision%7D.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.840 s
[INFO] Finished at: 2022-08-09T08:44:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project fc-service-server: Could not resolve dependencies for project eu.gaiax.difs.fc:fc-service-server:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at eu.gaiax.difs.fc:fc-service-api:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for eu.gaiax.difs.fc:fc-service-api:jar:0.0.1-SNAPSHOT: Could not find artifact eu.gaiax.difs.fc:fc-service:pom:${revision} in central (https://repo.maven.apache.org/maven2) -> [Help 1]

The maven convention for sub projects is:

    <parent>
        <groupId>eu.gaiax.difs.fc</groupId>
        <artifactId>fc-service</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>fc-service-server</artifactId>

So using the actual version number in the <parent> definition, and no version number for the project itself. To reference the version of the (parent) project, ${project.version} can be used:

    <dependency>
        <groupId>eu.gaiax.difs.fc</groupId>
        <artifactId>fc-service-api</artifactId>
        <version>${project.version}</version>
    </dependency>

Changing the version number for all sub-projects is a matter of one command:

mvn versions:set -DgenerateBackupPoms=false -DnewVersion=[new_version]

I can make a merge request to fix this issue.