Skip to content

Instantly share code, notes, and snippets.

@itzg
Last active January 16, 2022 10:03
Show Gist options
  • Save itzg/9276597 to your computer and use it in GitHub Desktop.
Save itzg/9276597 to your computer and use it in GitHub Desktop.
If you have one application jar with several main entry point classes, you can have Gradle produce a wrapper script for as many of those as you need.
apply plugin: 'groovy'
apply plugin: 'application'
startScripts.deleteAllActions()
jar {
manifest {
// Make sure the app's jar can be used with a simple -cp
attributes 'Class-Path': configurations.runtime.collect { "${it.getName()}" }.join(' ')
}
}
// copy the dependency jars alongside the built jar for development-time running
jar << {
copy {
from files(configurations.runtime)
into 'build/libs'
}
}
task app1StartScript(type:CreateStartScripts) {
applicationName = 'app1'
classpath = jar.outputs.files
mainClassName = 'com.example.AppMain1'
outputDir = file('build/bin')
}
task app2StartScript(type:CreateStartScripts) {
applicationName = 'app2'
classpath = jar.outputs.files
mainClassName = 'com.example.AppMain2'
outputDir = file('build/bin')
}
applicationDistribution.from(app1StartScript) {
into 'bin'
}
applicationDistribution.from(app2StartScript) {
into 'bin'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment