1

i am using the maven plugin:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>parse-version</id>
                    <goals>
                        <goal>parse-version</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

to parse the project version. It works fine:

[INFO] --- build-helper-maven-plugin:3.0.0:parse-version (parse-version)
[INFO]
[INFO] --- maven-antrun-plugin:1.1:run (default)
[INFO] Executing tasks

 [echo] Major: 2
 [echo] Minor: 0
 [echo] Incremental: 0
 [echo] Qualifier: SNAPSHOT
 [echo] BuildNumber: 0

but if i want to use the property parsedVersion.majorVersion in profile properties, it can't resolved.

    <profiles>
    <profile>
        <id>local</id>
        <properties>
            <majorVersion>${myMajorVersion}</majorVersion>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
</profiles>

<properties>
    <myMajorVersion>${parsedVersion.majorVersion}</myMajorVersion>

Any Idea?

Yanova
  • 11
  • 3

1 Answers1

0

The problem here is that property value substitutions are done at the time that the POM is read in, whereas the build-helper is run during the validation phase. Those properties aren't yet set when you read them in elements.

What you can probably do is set a property based on a regex using thee build-helper:regex-property Mojo (see https://www.mojohaus.org/build-helper-maven-plugin/regex-property-mojo.html). In your profile, you could set a property to a fixed value, and in the regex, it the value is matched, replace it with the parsed value you want. So long as the property value you are setting is used after the validate stage, then it will be set to the correct value where it is used.