Question

I have parent maven pom.xml like this:

<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>mygroup</groupId>
    <artifactId>mygroup-sharing</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <profiles>
        <profile>
            <id>linux-i386</id>
            <activation>
                <os>
                    <family>linux</family>
                    <arch>x86</arch>
                </os>
                <property>
                    <name>platform.suffix</name>
                    <value>linux-i386</value>
                </property>
            </activation>
        </profile>
        <profile>
            <id>solaris-i386</id>
            <activation>
                <os>
                    <family>solaris</family>
                    <arch>x86</arch>
                </os>
                <property>
                    <name>platform.suffix</name>
                    <value>solaris-i386</value>
                </property>
            </activation>
        </profile>
        ...
    </profiles>
    <properties>
        <depr.version>3.6.1-${platform.suffix}</depr.version>
    </properties>
</project>

and I have child (and I will have more) pom in subdirectory:

<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>

    <artifactId>mygroup-submodule</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>mygroup</groupId>
        <artifactId>mygroup-sharing</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../</relativePath>
    </parent>

    ...

    <dependencies>
        ...

        <dependency>
            <groupId>mygroup</groupId>
            <artifactId>depr</artifactId>
            <version>${depr.version}</version>
        </dependency>

        ...
    </dependencies>
</project>

The problem is, that the version is badly used when trying to compile the child project:

Downloading: http://myserver/nexus/content/groups/public//mygroup/depr/3.6.1-${platform.suffix}/depr-3.6.1-${platform.suffix}.pom
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) mygroup:depr:jar:3.6.1-${platform.suffix}

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
        1) mygroup:mygroup-submodule:jar:1.0-SNAPSHOT
        2) mygroup:depr:jar:3.6.1-${platform.suffix}

----------
....

... so as you can see, the property platform.suffix is badly applied when using the parent pom.

Also there's warning when running mvn -X install [WARNING] Overriding profile: 'linux-i386' (source: pom) with new instance from source: pom but there's no definition of profiles in the child pom file.

If I use this in each pom.xml file, it works properly. But I don't want to have copy-pasted this long part of pom.xml as it also can be extended (with more platforms).

Is there any other way how to share this type (platform suffix) configuration across other modules ?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top