Recommand · October 14, 2021 0

maven child modules not inheriting repository tags

I’ve declared release and snapshot repositories in the parent POM so as to make them available to all child modules

Here’s the parent repository tag

<repositories>
    <repository>
        <id>foo-releases</id>
        <url>https://nexusrm.cloud.bar.com/repository/foo-releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    <repository>
        <id>foo-milestones</id>
        <url>https://nexusrm.cloud.bar.com/repository/foo-milestones/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    <repository>
        <!-- bleeding edge -->
        <id>foo-snapshots</id>
        <url>https://nexusrm.cloud.bar.com/repository/foo-snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

We also have a mirror but that is mapped to central spring-milestones and spring-releases only

<mirrors> 
    <mirror>
    <id>bar-maven-mirror</id>
    <name>bar Hosted Maven Mirror</name>
    <url>https://nexusrm.cloud.bar.com/repository/maven-public/</url>
    <mirrorOf>!foo-snapshots,!foo-releases,!foo-milestones,!lp-snapshots,!lp-releases,*</mirrorOf>
    </mirror>
</mirrors>  

The build in my child module fails with the following error unless I copy the <repositories> tag to it; which of course is redundant

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.bar.cloud:foo-kafka-client:1.0.0-SNAPSHOT (/Users/anadimisra/code/bar/foo/libraries/foo-kafka-client/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.bar.cloud:foo-kafka-client:1.0.0-SNAPSHOT: Could not find artifact com.bar.cloud:foo:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

I declare the parent in kafka-client

<parent>
    <groupId>com.bar.cloud</groupId>
    <artifactId>foo</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

Have you tried a ‘maven install’ on your parent first? If it is not installed in your local maven repository, other libraries won’t find it.

Also why use another versioning scheme for your parent (e.g 1.0-SNAPSHOT) than your child (e.g. 1.0.0-SNAPSHOT). I do not think that this is an error but you can also have Bugfixes in your parent project. And it’s nice for the sake of consistency