The gradle-launch4j plugin uses launch4j3.14 to create windows .exe files for java applications.
This plugin is compatible with the Gradle versions 2 and later.
Since version 2.5 this plugin requires *Java 8, as launch4j in version 3.14 requires that as well.
If you are still forced to work with Java 6, use the latest version 2.4.
Tasks
There are 3 tasks:
createExe - Backward compatible task to generate an .exe file. Execute this task to generate an executable. With default settings this creates the executable under ${project.buildDir}/launch4j and puts all runtime libraries into the lib subfolder.
createAllExecutables - Helper task to run all tasks of the Launch4jExternalTask and Launch4jLibraryTask type.
launch4j - Deprecated placeholder task that depends on the above. This task was deprecated in favor of the createExe task and to avoid the name conflict of launch4j on the project.
Launch4j no longer needs to be installed separately, but if you want, you can still use it from the PATH. Since version 2.0 use the Launch4jExternalTask to create your executable.
Configuration
The configuration follows the structure of the launch4j xml file. The gradle-launch4j plugin tries to pick sensible defaults based on the project. The only required
value is the mainClassName.
How to include
An example configuration within your build.gradle for use in all Gradle versions might look like:
plugins {
id 'java'
id 'edu.sc.seis.launch4j' version '2.5.3'
}
launch4j {
mainClassName = 'com.example.myapp.Start'
icon = "${projectDir}/icons/myApp.ico"
}
If no repository is configured before applying this plugin the Maven central repository will be added to the project.
See the Gradle User guide for more information on how to use a custom plugin and the plugin page for the above settings.
How to configure
The values configurable within the launch4j extension along with their defaults are:
Property Name
Default Value
Comment
String outputDir
"launch4j"
This is the plugin's working path relative to $buildDir. Use the distribution plugin or a custom implementation to copy necessary files to an output location instead of adjusting this property.
String libraryDir
"lib"
Object copyConfigurable
null
User-redefined set of files to be copied into libraryDir (if not set the default logic of copying will be executed)
Set<String> classpath
[]
User-redefined classpath property (if not set the default logic based on the set of copied to libraryDir files will be used)
String xmlFileName
"launch4j.xml"
String mainClassName
boolean dontWrapJar
false
String headerType
"gui"
String jar
"lib/"+project.tasks[jar].archiveName or "", if the JavaPlugin is not loaded
In order to configure the input of the copyL4jLib task set the copyConfigurable property.
The following example shows how to use this plugin hand in hand with the shadow plugin:
If you use the outdated fatJar plugin the following configuration correctly wires the execution graph:
fatJar {
classifier 'fat'
with jar
manifest {
attributes 'Main-Class': project.mainClassName
}
}
fatJarPrepareFiles.dependsOn jar
launch4j {
outfile = 'TestMain.exe'
mainClassName = project.mainClassName
copyConfigurable = []
jarTask = project.tasks.fatJar
}
Launch4jLibraryTask
This task type can be used to build multiple executables with Launch4j. The default launch4j configuration from how to configure is used for the default values but can be adjusted.
To avoid replacing the resulting xml file or executable on each invocation, xmlFileName and outfile are set to the task name (name.xml and name.exe respectively).
To get insight into the launch4j creation process start a launch4j task, e.g. createExe, createExecutables or your custom task, with the script parameter -Pl4j-debug. This will copy the created xml into ${buildDir}/tmp/${task.name}.
In order to debug the created executable call it with the command line argument --l4j-debug. This will create the log file launch4j.log next to the executable.
Using SNAPSHOT versions
When you report a bug and it got fixed, you will have access to some -SNAPSHOT version.
Adjust your buildscript to use the OJO repo:
请发表评论