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

resolveCiFriendliesOnly doesn't resolve the ${revision} of the dependencies if revision is defined in the properties #120

Open
robertobatts opened this issue Dec 9, 2019 · 3 comments

Comments

@robertobatts
Copy link
Contributor

robertobatts commented Dec 9, 2019

I have a parent pom in a multimodule project like with a submodule and the revision defined in the properties:

<modules>
    <module>child-pom</module>
</modules>
<properties>
    <revision>1.0</revision>
</properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.1.0</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                </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>
                <inherited>true</inherited>
            </plugin>
        </plugins>
    </build>

I also have dependencies with version=${revision} in the parent as well as in the child. The problem is that in the child the version of the dependencies are not resolved.
It works fine if I define the revision value in the maven options (e.g. mvn install -Drevision=1.0), but not if I define it in the properties. Is this an expected behaviour?

@robertobatts robertobatts changed the title resolveCiFriendliesOnly doesn't resolve the ${revision} of the dependencies resolveCiFriendliesOnly doesn't resolve the ${revision} of the dependencies if revision is defined in the properties Dec 10, 2019
@omacarena
Copy link

Same as of version 1.2.5.
${revision} is replaced only for project version and parent version in child modules.

A way to solve this, for the moment, would be to define an additional property:

<properties>
  <revision>1.0</revision>
  <my-proj.version>${revision}</my-proj.version>
</properties>

After flattening, the property value will become frozen, same as ${revision}, but will protect against reusing one deployed POM into another project which defines its own ${revision} value.

Then just use <version>${my-proj.version}</version> for each of the dependencies having a module in the multi-module project.
If we think about it, might be even prettier having variables in a reusable POM than hardcoded values.

@xiaofud
Copy link

xiaofud commented May 7, 2022

Any update on this issue? I'm facing exactly the same problem

@sanyarnd
Copy link

workaround

  1. Extract version from pom.xml in CI script
    REVISION=$(mvn help:evaluate -Dexpression=revision -q -DforceStdout)
    # or faster alternative
    REVISION=$(grep -oP '(?<=<revision>).*?(?=</revision>)' pom.xml)
  2. Use variable in your Maven CLI, it's also easy to add suffix/prefix as needed
    mvn verify  -Drevision=${REVISION}-${CI_COMMIT_SHA:0:10}

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

4 participants