api / org.gradle.api.tasks.application

Package org.gradle.api.tasks.application

Types

CreateStartScripts

open class CreateStartScripts : CreateStartScripts

Creates start scripts for launching JVM applications.

Example:

 task createStartScripts(type: CreateStartScripts) { outputDir = file('build/sample') mainClassName = 'org.gradle.test.Main' applicationName = 'myApp' classpath = files('path/to/some.jar') } 

Note: the Gradle "application" plugin adds a pre-configured task of this type named "startScripts".

The task generates separate scripts targeted at Microsoft Windows environments and UNIX-like environments (e.g. Linux, macOS). The actual generation is implemented by the #getWindowsStartScriptGenerator() and #getUnixStartScriptGenerator() properties, of type org.gradle.jvm.application.scripts.ScriptGenerator.

Example:

 task createStartScripts(type: CreateStartScripts) { unixStartScriptGenerator = new CustomUnixStartScriptGenerator() windowsStartScriptGenerator = new CustomWindowsStartScriptGenerator() } class CustomUnixStartScriptGenerator implements ScriptGenerator { void generateScript(JavaAppStartScriptGenerationDetails details, Writer destination) { // implementation } } class CustomWindowsStartScriptGenerator implements ScriptGenerator { void generateScript(JavaAppStartScriptGenerationDetails details, Writer destination) { // implementation } } 

The default generators are of the type org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator, with default templates. This templates can be changed via the org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator#setTemplate(org.gradle.api.resources.TextResource) method.

The default implementations used by this task use Groovy's SimpleTemplateEngine to parse the template, with the following variables available:

  • applicationName
  • optsEnvironmentVar
  • exitEnvironmentVar
  • mainClassName
  • defaultJvmOpts
  • appNameSystemProperty
  • appHomeRelativePath
  • classpath

Example:

 task createStartScripts(type: CreateStartScripts) { unixStartScriptGenerator.template = resources.text.fromFile('customUnixStartScript.txt') windowsStartScriptGenerator.template = resources.text.fromFile('customWindowsStartScript.txt') }