# CreateStartScripts

API Documentation: | `CreateStartScripts`

Creates start scripts for launching JVM applications.

Example:

    task createStartScripts(type: CreateStartScripts) {
      outputDir = file('build/sample')
      mainClass = '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` - See `JavaAppStartScriptGenerationDetails.getApplicationName()`.
- `gitRef` - See `JavaAppStartScriptGenerationDetails.getGitRef()`.
- `optsEnvironmentVar` - See `JavaAppStartScriptGenerationDetails.getOptsEnvironmentVar()`.
- `exitEnvironmentVar` - See `JavaAppStartScriptGenerationDetails.getExitEnvironmentVar()`.
- `moduleEntryPoint` - The module entry point, or `null` if none. Will also include the main class name if present, in the form `[moduleName]/[className]`.
- `mainClassName` - The main class name, or usually `""` if none. For legacy reasons, this may be set to `--module [moduleEntryPoint]` when using a main module. This behavior should not be relied upon and may be removed in a future release.
- `entryPointArgs` - The arguments to be used on the command-line to enter the application, as a joined string. It should be inserted before the program arguments.
- `defaultJvmOpts` - See `JavaAppStartScriptGenerationDetails.getDefaultJvmOpts()`.
- `appNameSystemProperty` - See `JavaAppStartScriptGenerationDetails.getAppNameSystemProperty()`.
- `appHomeRelativePath` - The path, relative to the script's own path, of the app home.
- `classpath` - See `JavaAppStartScriptGenerationDetails.getClasspath()`. It is already encoded as a joined string.
- `modulePath` (different capitalization) - See `JavaAppStartScriptGenerationDetails.getModulePath()`. It is already encoded as a joined string.

The encoded paths expect a variable named `APP_HOME` to be present in the script, set to the application home directory which can be resolved using `appHomeRelativePath`.

Example:

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

### Properties

Property | Description
`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` | The directory to write the scripts into in the distribution.
`mainClass` | The main class name used to start the Java application.
`mainModule` | The main module name used to start the modular Java application.
`optsEnvironmentVar` | The environment variable to use to provide additional options to the JVM.
`outputDir` | Replaced 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

#### ``Property`<`String`>` `applicationName`

The application's name.

#### `ConfigurableFileCollection` `classpath`

The class path for the application.

#### ``ListProperty`<`String`>` `defaultJvmOpts`

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

#### ``Property`<`String`>` `executableDir`

The directory to write the scripts into in the distribution.

#### ``Property`<`String`>` `mainClass`

The main class name used to start the Java application.

#### ``Property`<`String`>` `mainModule`

The main module name used to start the modular Java application.

#### ``Property`<`String`>` `optsEnvironmentVar`

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

#### `File` `outputDir`

Note: This property has been replaced by outputDirectory.

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`.