Skip to content

CoolBalance/nsis-maven-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NSIS Maven Plugin

Maven Central

This Maven plugin allows you to build NSIS executables during your Maven build. It is based on the nsis-maven-plugin that used to be hosted at the CodeHaus SVN. Significant changes have been made, so this is not a drop-in replacement. This plugin should be able to do everything the original plugin can and more.

Table of Contents

1. Configuration

The plugin must be configured in the project's pom.xml to know what to do. The goals are executed using execution sections. A detailed description of the configuration options for the goals is given below.

1.1 Goal generate-headerfile

This goal generates a header file containing NSIS variables that represent common POM values. The resulting header file is automatically included in the NSIS script file.

Custom variables defined in defines will also be included in the generated header file.

The standard variables are:

  • PROJECT_BASEDIR
  • PROJECT_BUILD_DIR
  • PROJECT_FINAL_NAME
  • PROJECT_CLASSIFIER
  • PROJECT_GROUP_ID
  • PROJECT_ARTIFACT_ID
  • PROJECT_NAME
  • PROJECT_VERSION
  • PROJECT_PACKAGING
  • PROJECT_URL
  • PROJECT_LICENSE
  • PROJECT_LICENSE_URL
  • PROJECT_ORGANIZATION_NAME
  • PROJECT_ORGANIZATION_URL
  • PROJECT_REG_KEY
  • PROJECT_REG_UNINSTALL_KEY
  • PROJECT_STARTMENU_FOLDER

Variables where no value can be resolved will be omitted. If there are multiple licenses defined, the license defines will be PROJECT_LICENSE<n> and PROJECT_LICENSE<n>_URL instead, where <n> is the license number starting with 1.

1.1.1 Parameter description

Name Property Type Default Description
classifier nsis.classifier String The classifier to append to outputFile's name.
defines Map A list of one or more elements. The element name will become the !define name (converted to upper-case) and the element value will become the !define value. Example:

<foo>bar</foo> will result in !define FOO "bar"
disabled nsis.disabled Boolean false Deactivates all goals.
headerFile nsis.headerfile String project.nsh The path of the header file to generate.

1.2 Goal make

This goal compiles a NSIS script and builds a Windows executable.

1.2.1 Parameter description

Name Property Type Default Description
attachArtifact nsis.attachArtifact Boolean true Whether or not outputFile should be attached to the Maven build. You probably want an installer to be attached, but if you build another executable that might not be the case.
autoNsisDir nsis.auto.nsisdir Boolean true Whether or not to automatically set the NSISDIR environment variable based on the folder where the makensis executable is located. Useful when makensis is compiled with NSIS_CONFIG_CONST_DATA_PATH=no.
classifier nsis.classifier String The classifier to append to outputFile's name.
compression nsis.compression Enum zlib The compression type to apply to scriptFile if ant. See separate definition.
compressionDictSize nsis.compression.lzma.dictsize Integer 8 The dictionary size to use if compression is lzma.
compressionIsFinal nsis.compression.final Boolean false Whether or not the compression defined in compression isFINAL.
compressionIsSolid nsis.compression.solid Boolean false Whether or not the compression defined in compression isSOLID.
disabled nsis.disabled Boolean false Deactivates all goals.
environmentVariables Map A list of one or more elements. The element name will become the environment variable name and the element value will become the variable value. Example:

<foo>bar</foo> will result in an environment variable foo with the value bar.
headerFile nsis.headerfile String project.nsh The path of the generated header file.
injectHeaderFile nsis.headerfile.inject Boolean true Whether or not headerFile should be automatically injected as an !include in scriptFile. This is handy because it automatically makes sure that the correct path is used, but it means scriptFile won't compile if used without this plugin.
makeFolder nsis.makefolder String The folder to use as the working folder when running makensis. Relative paths will be resolved from this folder. By default this is the folder where scriptFile is located.
makensisExecutable nsis.makensis.executable String makensis The path of the makensis executable to use. The default assumes that makensis can be found in the OS path.
makensisExecutableLinux nsis.makensis.executable.linux String The path of the makensis executable to use if the build platform is Linux. If not configured, makensisExecutable will be used also on Linux.
makensisExecutableMacOS nsis.makensis.executable.macos String The path of the makensis executable to use if the build platform is macOS. If not configured, makensisExecutable will be used also on macOS.
nsisDir nsis.nsisdir String The value to use as NSISDIR. This will override autoNsisDir and the environment variable named NSISDIR if set.
outputFile nsis.output.file String ${project.build. finalName}.exe The path of the executable file to build.
scriptFile nsis.scriptfile String setup.nsi The path of the NSIS script file to compile.
verbosityLevel nsis.verbosity Integer 2 The verbosity level to pass to makensis.

1.2.2 compression options

Code Default Description
zlib * The DEFLATE compression algorithm used in ZIP, gzip and others.
bzip2 The bzip2 compression using the Burrows–Wheeler algorithm.
lzma The Lempel–Ziv–Markov chain compression algorithm used by 7-zip.

1.3 Skeleton project configuration

Here is a skeleton project configuration showing the potential locations of all configuration options:

<project>
    <!-- ... -->
    <build>
        <!-- ... -->
        <plugins>
            <!-- ... -->
            <plugin>
                <groupId>org.digitalmediaserver</groupId>
                <artifactId>nsis-maven-plugin</artifactId>
                <version>...</version>
                <configuration>
                    <attachArtifact></attachArtifact>
                    <autoNsisDir></autoNsisDir>
                    <classifier></classifier>
                    <compression></compression>
                    <compressionDictSize></compressionDictSize>
                    <compressionIsFinal></compressionIsFinal>
                    <compressionIsSolid></compressionIsSolid>
                    <defines>
                        <FIRST_DEFINE>first define value</FIRST_DEFINE>
                        <SECOND_DEFINE>second define value</SECOND_DEFINE>
                        <!-- ... -->
                        <LAST_DEFINE>last define value</LAST_DEFINE>
                    </defines>
                    <disabled></disabled>
                    <environmentVariables>
                        <firstVariable>first variable value</firstVariable>
                        <secondVariable>second variable value</secondVariable>
                        <!-- ... -->
                        <lastVariable>last variable value</lastVariable>
                    </environmentVariables>
                    <headerFile></headerFile>
                    <injectHeaderFile></injectHeaderFile>
                    <makeFolder></makeFolder>
                    <makensisExecutable></makensisExecutable>
                    <makensisExecutableLinux></makensisExecutableLinux>
                    <makensisExecutableMacOS></makensisExecutableMacOS>
                    <nsisDir></nsisDir>
                    <outputFile></outputFile>
                    <scriptFile></scriptFile>
                    <verbosityLevel></verbosityLevel>
                </configuration>
                <executions>
                    <execution>
                        <id>execution-id</id>
                        <configuration>
                            <attachArtifact></attachArtifact>
                            <autoNsisDir></autoNsisDir>
                            <classifier></classifier>
                            <compression></compression>
                            <compressionDictSize></compressionDictSize>
                            <compressionIsFinal></compressionIsFinal>
                            <compressionIsSolid></compressionIsSolid>
                            <defines>
                                <FIRST_DEFINE>first define value</FIRST_DEFINE>
                                <SECOND_DEFINE>second define value</SECOND_DEFINE>
                                <!-- ... -->
                                <LAST_DEFINE>last define value</LAST_DEFINE>
                            </defines>
                            <disabled></disabled>
                            <environmentVariables>
                                <firstVariable>first variable value</firstVariable>
                                <secondVariable>second variable value</secondVariable>
                                <!-- ... -->
                                <lastVariable>last variable value</lastVariable>
                            </environmentVariables>
                            <headerFile></headerFile>
                            <injectHeaderFile></injectHeaderFile>
                            <makeFolder></makeFolder>
                            <makensisExecutable></makensisExecutable>
                            <makensisExecutableLinux></makensisExecutableLinux>
                            <makensisExecutableMacOS></makensisExecutableMacOS>
                            <nsisDir></nsisDir>
                            <outputFile></outputFile>
                            <scriptFile></scriptFile>
                            <verbosityLevel></verbosityLevel>
                        </configuration>
                        <goals>
                            <goal></goal>
                            <!-- ... -->
                        </goals>
                    </execution>
                    <!-- ... -->
                </executions>
            </plugin>
            <!-- ... -->
        </plugins>
        <!-- ... -->
    </build>
    <!-- ... -->
</project>

2. Using the plugin

This plugin performs two very different tasks in its two goals. The generate-headerfile goal generates a file that can be included in a NSIS script as an !include that contains values available in the POM. It defines a set of standard values plus any configured custom values. This header file is not needed by the make goal, but can be very useful to avoid having to maintain the same information in multiple files. If the header file exists and injectHeaderFile is true (default), no explicit !include is required in the script compiled in the make goal. While this is handy to not have to specify a valid path to where the header file is located in the NSIS script, it means that the NSIS script can no longer be compiled without using this plugin if any of the defined values is used in the script.

The make goal builds the Windows executable from the specified NSIS script. NSIS scripts can be used to make other types of executables than merely installers, like for example application launchers. The goals can be run multiple times in multiple executions, but unless the header file contains different values for the different NSIS scripts, there isn't much point in executing the generate-headerfile goal more than once. The generated file will stay available for reference or injection by subsequent make goals. The resulting .exe files will be attached to the Maven build like any other artifact unless attachArtifact is false. In this case, the .exe file will simply be generated and left in its target folder.

2.1 Example configuration

Here is an example configuration showing how to generate a header file, a Windows application launcher and a Windows installer:

<project>
    <!-- ... -->
    <build>
        <!-- ... -->
        <plugins>
            <!-- ... -->
            <plugin>
                <groupId>org.digitalmediaserver</groupId>
                <artifactId>nsis-maven-plugin</artifactId>
                <version>...</version>
                <configuration>
                    <makensisExecutable>${project.external-resources}/third-party/nsis/Bin/makensis.exe</makensisExecutable>
                    <makensisExecutableLinux>${project.external-resources}/third-party/nsis/Bin/makensisLinux</makensisExecutableLinux>
                    <makensisExecutableMacOS>${project.external-resources}/third-party/nsis/Bin/makensisMacOS</makensisExecutableMacOS>
                    <compression>lzma</compression>
                    <compressionIsFinal>true</compressionIsFinal>
                    <compressionDictSize>64</compressionDictSize>
                    <defines>
                        <PROJECT_NAME_SHORT>${project.name.short}</PROJECT_NAME_SHORT>
                        <PROJECT_NAME_CAMEL>${project.name.camel}</PROJECT_NAME_CAMEL>
                    </defines>
                </configuration>
                <executions>
                    <execution>
                        <id>build-windows-launcher</id>
                        <configuration>
                            <scriptFile>${project.external-resources}/nsis/${project.artifactId}.nsi</scriptFile>
                            <outputFile>${project.name.short}.exe</outputFile>
                            <attachArtifact>false</attachArtifact>
                        </configuration>
                        <goals>
                            <goal>generate-headerfile</goal>
                            <goal>make</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>build-windows-installer</id>
                        <configuration>
                            <scriptFile>${project.external-resources}/nsis/setup.nsi</scriptFile>
                            <outputFile>${project.name.short}-setup.exe</outputFile>
                        </configuration>
                        <goals>
                            <goal>make</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- ... -->
        </plugins>
        <!-- ... -->
    </build>
    <!-- ... -->
</project>

About

A Maven plugin for building NSIS installers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 97.9%
  • CSS 2.1%