The following was copied from an existing project and may use some things not included in the snippet (eg Nebula plugins):
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'com.example.Main'
jar {
manifest {
attributes 'Main-Class': 'com.example.Main'
}
}
publishing {
publications {
nebulaIvy(IvyPublication) {
artifact(tasks.findByName('createJarExe').outputs.getFiles().getSingleFile()) {
classifier '_-jdk8'
extension 'exe'
type 'exe'
}
}
}
}
task createJarExe(dependsOn: installShadowDist) {
final outputFile = file("${buildDir}/install/${project.name}-shadow/bin/${project.name}-${project.version}.exe")
doLast {
outputFile.text = '#!/bin/bash\n'
outputFile.append('exec java -jar "$0" "$@"')
outputFile.append(inputs.files.first().readBytes())
outputFile.setExecutable(true)
}
inputs.files "${tasks.findByName('installShadowDist').outputs.getFiles().getSingleFile()}/lib/${project.name}-${project.version}-all.jar"
outputs.file outputFile
doFirst {
mkdir outputFile.getParent()
}
}
// wire the dependencies
tasks.whenTaskAdded { task ->
if (task.name == 'publishNebulaIvyPublicationToDistIvyRepository') {
task.dependsOn('createJarExe')
}
}
Notes:
com.github.johnrengelman.shadow is used to create the uber-jar.
com.example.Main is the Java entry point for execution.
- Specifying the
classifier is more for the protoc Gradle plugin (which includes the OS in the classifier by default) and isn't strictly needed. Clients of the published protoc plugin must use versions 0.8.3 or higher of the protoc Gradle plugin which supports overriding the classifier.
createJarExe uses the uber-jar and follows the post on self-executing JAR files
wire the dependencies ensures that the uber-jar is created before distribution