0

I got my maven artefact version e.g. 1.2.3.4.5-SNAPSHOT which contains my official version (The version number actually visible to the customer) e.g. 1.2.3.4 as substring. Because I don't want to maintain two separate properties, I am extracting the product version out of the artefact version:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <id>plannedversion</id>
                        <goals>
                            <goal>regex-property</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <name>official.version</name>
                            <value>${project.version}</value>
                            <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(-SNAPSHOT)?$</regex>
                            <replacement>$1.$2.$3.$4</replacement>

                        </configuration>
                    </execution>
                </executions>
            </plugin>

That works quite well. If I print the version via ANT:

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo>******** Displaying value of property 'official.version' ********</echo>
                                <echo>${official.version}</echo>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I get

[echo] ******** Displaying value of property 'official.version' ********
[echo] 1.2.3.4

But if I try to use this property in any other plugin than ant, it is not evaluated.

  <plugin>
            <groupId>com.my.custom-plugin</groupId>
            <artifactId>releasenotes-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>releasenotes</id>
                    <goals>
                        <goal>releasenotes</goal>
                    </goals>
                    <phase>validate</phase>
                    <configuration>
                        <dataSources>
                            <jira>
                                <url>http://my-jira:8080/jira</url>
                                <jql>fixVersion = ${official.version}</jql>
                            </jira>
                        </dataSources>

                    </configuration>

                </execution>
            </executions>

        </plugin>

This returns Invalid JQL: 'fixVersion = ${official.version}' which shows that the maven property has not been replaced before running my release notes plugin.

The order above shows the actual plugin order within my pom.xml.

Why is the property correctly replaced when using ant, and why does this not work when using other plugins?

gorootde
  • 4,003
  • 4
  • 41
  • 83
  • Could it be that the expression `fixVersion = ${official.version}` is not evaluated by the plugin? – uniknow May 18 '16 at 11:46
  • Ive actually proven that this is not the case. The expression is evaluated before the plugin is called. If I change `official.version` to `project.version` everything works fine. – gorootde May 18 '16 at 11:49
  • You know that [maven-change-plugin](https://maven.apache.org/plugins/maven-changes-plugin/) already support extrating information from jira... – khmarbaise May 18 '16 at 12:37
  • @khmarbaise I know, but this plugin does not support Templating or other datasources than issue trackers. Mine does. The config above is just an excerpt. – gorootde May 18 '16 at 12:41
  • @k_wave, what happens when you replave `${official.version}` by `fixVersion = ${official.version}` ? – michaldo May 18 '16 at 12:54
  • Are you trying to create java template files ? Or what are you traing to achieve? Furthermore the filtering mechanism in Maven will handle that. By using either versions-maven-plugin or maven-release-plugin all that is handled already ... I don't undestand what kind of property handling you are doing here and what the real purpose of this is? – khmarbaise May 18 '16 at 13:04
  • @michaldo It prints `[echo] fixVersion = 1.2.3.4` – gorootde May 18 '16 at 13:49
  • What happens if you specify `official.version` as a regular property, and can you assure that the plugins are executed in the order you have defined them in the pom? – uniknow May 18 '16 at 14:15
  • @uniknow If I define it as regular property it is evaluated. In the log output I can see that the listing order in my pom is the actual execution order. – gorootde May 18 '16 at 14:29
  • Ok, strange. Usually the property name is shown in case the property is unknown/non existing but in your case it is printing when ANT plugin is executed and non existing anymore when release notes plugin is executed. Might it be that the ant plugin is 'resetting' the property (e.g. what is happening if you leave the ant plugin out) – uniknow May 18 '16 at 14:43
  • I'd try looking at the source code for the antrun plugin to see how it does property resolution. Perhaps it's handling things differently than your custom plugin, and you can get a clue for how to do it. Another alternative might be to use the GMaven plugin instead of build-helper to define `official.version`. I've used GMaven for [a similar task](http://stackoverflow.com/a/15962647/944849) in the past. – user944849 May 18 '16 at 15:00

0 Answers0