CreateStartScripts

API Documentation: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 CreateStartScripts.getWindowsStartScriptGenerator() and CreateStartScripts.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 TemplateBasedScriptGenerator, with default templates. This templates can be changed via the 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')
}

Properties

PropertyDescription
applicationName

The application's name.

classpath

The class path for the application.

defaultJvmOpts

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

executableDir
Incubating

The directory to write the scripts into in the distribution.

mainClassName

The main classname used to start the Java application.

optsEnvironmentVar

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

outputDir

The directory to write the scripts into.

unixStartScriptGenerator

The UNIX-like start script generator.

windowsStartScriptGenerator

The Windows start script generator.

Methods

No methods

Script blocks

No script blocks

Property details

String applicationName

The application's name.

FileCollection classpath

The class path for the application.

Iterable<String> defaultJvmOpts

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

String executableDir

Note: This property is incubating and may change in a future version of Gradle.

The directory to write the scripts into in the distribution.

String mainClassName

The main classname used to start the Java application.

String optsEnvironmentVar

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

File outputDir

The directory to write the scripts into.

ScriptGenerator unixStartScriptGenerator

The UNIX-like start script generator.

Defaults to an implementation of TemplateBasedScriptGenerator.

ScriptGenerator windowsStartScriptGenerator

The Windows start script generator.

Defaults to an implementation of TemplateBasedScriptGenerator.