Reputation: 13977
I want to use the value of the version field in my pom.xml for my nsis Windows installers. To do this I use the nsis-maven-plugin to generate a target/project.nsh
(which will contain an appropriate PROJECT_VERSION
field), that then gets !include
into my setup.nsi
.
Here's the problem: Suppose my pom project.version
is 1.2-SNAPSHOT. makensis
will fail with the error:
[MAKENSIS] Error: invalid VIProductVersion format, should be X.X.X.X
So I've got two problems:
The "-SNAPSHOT" string
I could chop it off before setting the VIProductVersion
field, but then my version will appear like 1.2 when it's really not.
My version looks like X.X, but needs to be X.X.X.X
Hard padding the field with two zeros (e.g. VIProductVersion ${PROJECT_VERSION}.0.0
) will just break as soon as I change my pom project.version
to 1.2.1
Is there a good strategy for this?
Upvotes: 0
Views: 1101
Reputation: 1
I had the exact same problem.
Since I use the copy-maven-problem in my project, I also used it to precess the project.nsh
with a Groovy snippet:
<resource>
<targetPath>${project.build.directory}</targetPath>
<file>${project.build.directory}/installer-header.nsh</file>
<destFileName>installer-header-processed.nsh</destFileName>
<!-- groovy extension point -->
<process>{{
def versionsList = project.version.replaceFirst("-SNAPSHOT", "").tokenize('.')
while(!(versionsList.size >= 4)){
versionsList.add('0')
}
files[0].append("!define VI_PRODUCT_VERSION \"" + versionsList.join('.') + "\"\n")
}}</process>
</resource>
<resource>
<targetPath>${project.build.directory}</targetPath>
<file>${project.build.directory}/installer-header-processed.nsh</file>
<destFileName>installer-header.nsh</destFileName>
<move>true</move>
</resource>
Check the doc to this plugin and adapt the variable/file names (i.e. I call the header file installer-header.nsh
)
After this, you have a variable VI_PRODUCT_VERSION
(rename as you want) in the header which you can use in your setup.nsi
.
I know this looks like q bad hack, but it works for now. I hope that there will be plugin-generated variables in the future..
PS: Call the copy-maven-plugin BEFORE nsis-maven-plugin within the packaging phase for it to work. I defined the copy plugin before the nsis plugin - the .nsh
is generated within the prepare-package phase, so it exists before the processing.
Upvotes: 0
Reputation: 101756
I don't know anything about maven but I can tell you why NSIS works like this.
You can use VIAddVersionKey
to add any string you want (Including "ProductVersion"). VIProductVersion
sets the fixed (VS_FIXEDFILEINFO) part of the win32/PE version resource, that is why it has to contain 4 16 bit numbers...
Upvotes: 1