api / org.gradle.jvm.application.tasks / CreateStartScripts

CreateStartScripts

open class CreateStartScripts : ConventionTask

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 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:

Example:

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

Constructors

<init>

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 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
  • executableDir
  • defaultJvmOpts
  • appNameSystemProperty
  • appHomeRelativePath
  • classpath

Example:

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

Functions

generate

open fun generate(): Unit

getApplicationName

open fun getApplicationName(): String

The application's name.

getClasspath

open fun getClasspath(): FileCollection

The class path for the application.

getDefaultJvmOpts

open fun getDefaultJvmOpts(): MutableIterable<String>

The application's default JVM options. Defaults to an empty list.

getExecutableDir

open fun getExecutableDir(): String

The directory to write the scripts into in the distribution.

getExitEnvironmentVar

open fun getExitEnvironmentVar(): String

The environment variable to use to control exit value (Windows only).

getMainClassName

open fun getMainClassName(): String

The main classname used to start the Java application.

getOptsEnvironmentVar

open fun getOptsEnvironmentVar(): String

The environment variable to use to provide additional options to the JVM.

getOutputDir

open fun getOutputDir(): File

The directory to write the scripts into.

getUnixScript

open fun getUnixScript(): File

Returns the full path to the Unix script. The target directory is represented by the output directory, the file name is the application name without a file extension.

getUnixStartScriptGenerator

open fun getUnixStartScriptGenerator(): ScriptGenerator

The UNIX-like start script generator.

Defaults to an implementation of org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator.

getWindowsScript

open fun getWindowsScript(): File

Returns the full path to the Windows script. The target directory is represented by the output directory, the file name is the application name plus the file extension .bat.

getWindowsStartScriptGenerator

open fun getWindowsStartScriptGenerator(): ScriptGenerator

The Windows start script generator.

Defaults to an implementation of org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator.

setApplicationName

open fun setApplicationName(applicationName: String): Unit

setClasspath

open fun setClasspath(classpath: FileCollection): Unit

setDefaultJvmOpts

open fun setDefaultJvmOpts(defaultJvmOpts: MutableIterable<String>): Unit

setExecutableDir

open fun setExecutableDir(executableDir: String): Unit

The directory to write the scripts into in the distribution.

setExitEnvironmentVar

open fun setExitEnvironmentVar(exitEnvironmentVar: String): Unit

setMainClassName

open fun setMainClassName(mainClassName: String): Unit

setOptsEnvironmentVar

open fun setOptsEnvironmentVar(optsEnvironmentVar: String): Unit

setOutputDir

open fun setOutputDir(outputDir: File): Unit

setUnixStartScriptGenerator

open fun setUnixStartScriptGenerator(unixStartScriptGenerator: ScriptGenerator): Unit

setWindowsStartScriptGenerator

open fun setWindowsStartScriptGenerator(windowsStartScriptGenerator: ScriptGenerator): Unit

Inheritors

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') }