0

I have the following parent pom

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>com.test.test</groupId>
    <artifactId>artifact-id</artifactId>
    <version>${revision}</version>
    <modules>
        <module>child1</module>
        <module>child2</module>
    </modules>
    <packaging>pom</packaging>

    <properties>
        <revision>1.0.0-SNAPSHOT</revision>
    <properties>
    <build>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>flatten-maven-plugin</artifactId>
            <version>${flatten.version}</version>
            <configuration>
                <updatePomFile>true</updatePomFile>
            </configuration>
            <executions>
                <execution>
                    <id>flatten</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>flatten</goal>
                    </goals>
                </execution>
                <execution>
                    <id>flatten.clean</id>
                    <phase>clean</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
</plugins>

... and child pom:

    <parent>
        <groupId>com.test.test</groupId>
        <artifactId>artifact-id</artifactId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>child-pom</artifactId>

And I want to build the project from Jenkins with -Drevision=.... So far so good, but in the maven repository (local one) the pom file of the child is with ${revision} in it so it can't be resolved later. The flatten plugin produces some pom xml files but they are not used obviously. Any suggestions how can I fix that? Also it will be great if I'm able to build each child module separately from the parent. Maven - 3.5.3 Java - 8 and I have a shade plugin in the parent pom too.

Georgi Stoyanov
  • 469
  • 1
  • 5
  • 24
  • 1
    Running only the submodule: https://stackoverflow.com/questions/1114026/maven-modules-building-a-single-specific-module – Randy Apr 25 '18 at 05:58
  • Yep, it worked. – Georgi Stoyanov Apr 25 '18 at 06:06
  • I have doubts about having shade plugin in parent cause in parent you don't have code so it can't really be used... – khmarbaise Apr 25 '18 at 06:41
  • If you have pom files in your local repository which contain `${revision}` than something is wrong...If you have submodules you should only use `mvn -pl ...` from the root and don't go to the sub directory...etc. – khmarbaise Apr 25 '18 at 06:50
  • @khmarbaise yep, something is wrong. The thing is when I do `mvn clean install -Drevision=1.2.3` it creates a jar with that version, it uses it in generated inside the jar pom.xml but in the prjectName.pom file (that is in the local repo) it's with just `${revision}` – Georgi Stoyanov Apr 25 '18 at 07:11
  • Using variables for a project's version is not a good idea. You should use the maven release and version plugins to manage your versions. – Ralf Apr 25 '18 at 07:43
  • @Ralf sorry for the lame question but how can I do that and integrate it with jenkins? I'm thinking to add version plugin and set a goal to update child poms on clean phase? And another thing - I have core child project that other projects depends on it and it's version. Can I do it work with version plugin again? – Georgi Stoyanov Apr 25 '18 at 07:56
  • For multi-module projects all you need to do is repeat the version of the parent in the child POMs. If your reactor (parent) POM has the version 1.0.0-SNAPSHOT repeat this when referencing the parent in the child POMs. The [release plugin](http://maven.apache.org/maven-release/maven-release-plugin/) takes care of updating the version dependency on release. – Ralf Apr 25 '18 at 08:20
  • but we want to change versions on each commit, so it will be easy to revert/checkout a specific version and devops wants to set it in Jenkins and then deploy – Georgi Stoyanov Apr 25 '18 at 08:32
  • @GeorgiStoyanov Can you make an example project on github so I can take a look into it... – khmarbaise Apr 25 '18 at 11:15
  • It was misunderstood - we don't change the versions but add Timestamps. – Georgi Stoyanov Apr 25 '18 at 14:20

0 Answers0