Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use parent with relativePath? #126

Open
CarstenWickner opened this issue Sep 23, 2021 · 1 comment
Open

How to use parent with relativePath? #126

CarstenWickner opened this issue Sep 23, 2021 · 1 comment

Comments

@CarstenWickner
Copy link

We have separated one of our projects into two pom.xml files and make use of the <parent>/<relativePath> property.

  1. A simple but technical "main" pom.xml, that is properly versioned and checked-in:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.example</groupId>
    <artifactId>example-war</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>example-war</name>

    <parent>
        <groupId>my.example</groupId>
        <artifactId>example-war-parent</artifactId>
        <version>1.0</version>
        <relativePath>example-war-parent.xml</relativePath>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>io.repaint.maven</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>2.23</version>
                <extensions>true</extensions>
                <configuration>
                    <tiles>
                        <tile>my.example.maven-tile:war-tile:1.0</tile>
                    </tiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. a local parent POM (which is auto-generated in the CI process), containing all the things we want to include in the war artifact:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.example</groupId>
    <artifactId>example-war-parent</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <name>example-war-parent</name>

    <dependencies>
        <dependency>
            <groupId>my.example</groupId>
            <artifactId>dynamically-built-stuff</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

When running a local build, one ends up with:

--- tiles-maven-plugin: Injecting 2 tiles as intermediary parent artifacts for com.torqueits:cpms-war...
Mixed 'my.example:example-war:1.0.0-SNAPSHOT' with tile 'my.example.maven-tile:war-tile:1.0' as its new parent.
Mixed 'my.example.maven-tile:war-tile:1.0' with tile 'my.example.maven-tile:nexus-tile:1.0' as its new parent.
Mixed 'my.example.maven-tile:nexus-tile:1.0' with original parent 'my.example:example-war-parent:1.0' as its new top level parent.

Downloading from nexus: https://my.example.com/nexus/content/groups/public/my/example/example-war-parent/1.0/example-war-parent-1.0.pom
Error executing Maven.
Missing:
----------
1) my.example:example-war-parent:pom:1.0
----------
1 required artifact is missing.

for artifact: 
  my.example:example-war-parent:pom:1.0

from the specified remote repositories:
  nexus (https://my.example.com/nexus/content/groups/public, releases=true, snapshots=true)

In our CI environment, we workaround this issue by first installing the parent POM locally before running the main build:

mvn clean install -f example-war-parent.xml
mvn clean install

In a local IDE/build scenario, this extra step is a hassle.
Is there a way to respect the parent's <relativePath> instead of attempting to take it from the (possibly outdated) local/remote repository?

@talios
Copy link
Member

talios commented Dec 26, 2022

Just following up on this as I seem to have missed it. Looking at the chain of the code the relative path is preserved in the Parent model class, and we're just reusing that instance when we reattach it to the end of the inheritance chain - so this should work.

I wonder if removing the <version>1.0</version> from your parent declaration makes any difference - it may be that Maven is taking the version number in preference, and looking it up in a remote/local repository as it's not in any reactor?

I'll pull those two pom's out into a CI test to add into the project and give it a try in the morning.

I have added a bit of extra logging there to cover/document the relative path in the mean time as part of testing:

[INFO] --- tiles-maven-plugin: Injecting 1 tiles as intermediary parent artifacts for com.test:civersion-tiletest-ciparent...
[INFO] Mixed 'com.test:civersion-tiletest-ciparent:0.1.0-SNAPSHOT' with tile 'com.test:civersion-tiletest-tile2:1' as its new parent.
[INFO] Mixed 'com.test:civersion-tiletest-tile2:1' with original parent 'com.test:civersion-tiletest-parent3:0.1.0-SNAPSHOT' via ../parent3/pom.xml as its new top level parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants