Generating .obr file: how to resolve buildNumber?

Hello,

I would like to use the Build Number Maven Plugin to have a build number added to the version automatically.

The final name is defined as follows in the build section of the pom.xml:

<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>

It works fine as far as the creation of the .jar file is concerned but fails for the creation of the .obr file because it cannot resolve “$buildNumber”:

[ERROR] Failed to execute goal com.atlassian.maven.plugins:maven-confluence-plugin:6.3.15:generate-obr-artifact (default-generate-obr-artifact) on project test: Source '...\target\test-0.3.0.${buildNumber}.jar' does not exist -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

Any suggestions how to get it working?

Thanks
Christian

1 Like

I’ve the same issue. Did you solve it ?

No, unfortunately not and I haven’t received any feedback so far.

Are you using Linux ? I’ve tried to bypass the problem with few lines in bash. I could post them.

Yes, it would be great if you can post your solution.

It’s not sophisticated but it works. Maybe you can improve it.
First in your pom.xml write your version with buildnumber, in format <version>1.0.0.0</version>
Then create a new script (e.g. change_buildnumber.sh) into which you can put these few bash commands.

#!/bin/bash

version=`cat pom.xml | grep -m 1 "<version>.*<\/version>" | awk -F'[><]' '{print $3}' | cut -d. -f-3`
#old_buildnumber=`cat buildNumber.properties | grep buildNumber= | cut -d= -f2`
old_buildnumber=`cat pom.xml | grep -m 1 "<version>.*<\/version>" | awk -F'[><]' '{print $3}' | cut -d. -f4`
new_buildnumber=$((old_buildnumber+1))
cp pom.xml pom.xml.backup
cat pom.xml.backup | sed -r -e "s/<version>$version.$old_buildnumber<\/version>/<version>$version.$new_buildnumber<\/version>/g" > pom.xml

It will increment and replace the buildnumber and it will also create a backup pom.xml.
The commented lines are an alternative method to get the buildnumber from the file buildNumber.properties instead that from pom.xml
Currently I use a script that calls this one before calling atlas-package
Hope this helps

P.S: With this script in my pom.xml I have
<finalName>${project.artifactId}-${project.version}</finalName>

That’s great, thank you.

I will check for a solution that works on Windows too (as I use both).

It will be hard to replace awk and sed :smiley:
If you succeed in this, post your solution here, please. Thanks

1 Like

Hard to replace awk and sed, yes, but you can do an end run with PowerShell, which can read the XML, treating elements and attributes as properties (a la Groovy, but more compactly (at least in this context)) and then write the XML back out.

Also (this may or may not apply, I’m not familiar with Maven or how it integrates with Bamboo), we use a dummy Bamboo Deployment to increment the build number (since this seems to be the approach that makes Bamboo happiest).

2 Likes