简体   繁体   中英

Populate VIProductVersion with nsis-maven-plugin

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:

  1. 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.

  2. My version looks like XX, but needs to be XXXX

    Hard padding the field with two zeros (eg 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?

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...

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM