# Class CreateStartScripts

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.jvm.application.tasks.CreateStartScripts

All Implemented Interfaces:
  `Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, Named, ExtensionAware, Task, Configurable<Task>`

Direct Known Subclasses:
  `CreateStartScripts`

@DisableCachingByDefault(because="Not worth caching") public abstract class CreateStartScripts extends org.gradle.api.internal.ConventionTask
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 `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 `TemplateBasedScriptGenerator`, with default templates. This templates can be changed via the `TemplateBasedScriptGenerator.setTemplate(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')
    }

Since:
  2.4

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface Named

  `Named.Namer`

- ## Field Summary

  ### Fields inherited from interface Task

  `TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CreateStartScripts()`
  Creates a new `CreateStartScripts`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `generate()`
  Generate.
  `@Nullable String`
  `getApplicationName()`
  The application's name.
  `@Nullable FileCollection`
  `getClasspath()`
  The class path for the application.
  `@Nullable Iterable<String>`
  `getDefaultJvmOpts()`
  The application's default JVM options.
  `String`
  `getExecutableDir()`
  The directory to write the scripts into in the distribution.
  `@Nullable String`
  `getExitEnvironmentVar()`
  Deprecated.
  No longer used in the default start script templates.
  `abstract Property<String>`
  `getGitRef()`
  The Git revision or tag.
  `protected abstract org.gradle.internal.jvm.JavaModuleDetector`
  `getJavaModuleDetector()`
  `abstract Property<String>`
  `getMainClass()`
  The main class name used to start the Java application.
  `abstract Property<String>`
  `getMainModule()`
  The main module name used to start the modular Java application.
  `ModularitySpec`
  `getModularity()`
  Returns the module path handling for executing the main class.
  `protected abstract ObjectFactory`
  `getObjectFactory()`
  `@Nullable String`
  `getOptsEnvironmentVar()`
  The environment variable to use to provide additional options to the JVM.
  `@Nullable File`
  `getOutputDir()`
  The directory to write the scripts into.
  `abstract DirectoryProperty`
  `getOutputDirectory()`
  The directory to write the scripts into.
  `protected abstract ProviderFactory`
  `getProviderFactory()`
  `protected Iterable<String>`
  `getRelativeClasspath()`
  Returns the relative classpath.
  `File`
  `getUnixScript()`
  Returns the full path to the Unix script.
  `abstract RegularFileProperty`
  `getUnixScriptFile()`
  Returns the full path to the Unix script.
  `ScriptGenerator`
  `getUnixStartScriptGenerator()`
  The UNIX-like start script generator.
  `File`
  `getWindowsScript()`
  Returns the full path to the Windows script.
  `abstract RegularFileProperty`
  `getWindowsScriptFile()`
  Returns the full path to the Windows script.
  `ScriptGenerator`
  `getWindowsStartScriptGenerator()`
  The Windows start script generator.
  `void`
  `setApplicationName(@Nullable String applicationName)`
  Sets the application name.
  `void`
  `setClasspath(@Nullable FileCollection classpath)`
  Sets the classpath.
  `void`
  `setDefaultJvmOpts(@Nullable Iterable<String> defaultJvmOpts)`
  Sets the default jvm opts.
  `void`
  `setExecutableDir(String executableDir)`
  The directory to write the scripts into in the distribution.
  `void`
  `setExitEnvironmentVar(@Nullable String exitEnvironmentVar)`
  Deprecated.
  `void`
  `setOptsEnvironmentVar(@Nullable String optsEnvironmentVar)`
  Sets the opts environment var.
  `void`
  `setOutputDir(@Nullable File outputDir)`
  Sets the output dir.
  `void`
  `setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)`
  Sets the unix start script generator.
  `void`
  `setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)`
  Sets the windows start script generator.

  ### Methods inherited from class org.gradle.api.internal.ConventionTask

  `conventionMapping, conventionMapping, getConventionMapping`

  ### Methods inherited from class DefaultTask

  `compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService`

  ### Methods inherited from class org.gradle.api.internal.AbstractTask

  `acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getLoggingManager, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, service, setImpliesSubProjects`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface Task

  `doNotTrackState, notCompatibleWithConfigurationCache, service`

- ## Constructor Details

  - ### CreateStartScripts

    public CreateStartScripts()
    Creates a new `CreateStartScripts`.
    Since:
      2.4

- ## Method Details

  - ### getObjectFactory

    @Inject protected abstract ObjectFactory getObjectFactory()

  - ### getProviderFactory

    @Inject protected abstract ProviderFactory getProviderFactory()

  - ### getJavaModuleDetector

    @Inject protected abstract org.gradle.internal.jvm.JavaModuleDetector getJavaModuleDetector()

  - ### getOptsEnvironmentVar

    @Optional @Input public @Nullable String getOptsEnvironmentVar()
    The environment variable to use to provide additional options to the JVM.
    Since:
      2.4

  - ### getExitEnvironmentVar

    @Optional @Input @Deprecated public @Nullable String getExitEnvironmentVar()
    Deprecated.
    No longer used in the default start script templates. Will be removed in Gradle 10.
    The environment variable to use to control exit value (Windows only).
    Since:
      2.4

  - ### getUnixScriptFile

    @Incubating @Internal public abstract RegularFileProperty getUnixScriptFile()
    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.
    Since:
      9.7.0

  - ### getUnixScript

    @ReplacedBy("unixScriptFile") public File getUnixScript()
    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.
    Since:
      2.4

  - ### getWindowsScriptFile

    @Incubating @Internal public abstract RegularFileProperty getWindowsScriptFile()
    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.
    Since:
      9.7.0

  - ### getWindowsScript

    @ReplacedBy("windowsScriptFile") public File getWindowsScript()
    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.
    Since:
      2.4

  - ### getOutputDirectory

    @Incubating @OutputDirectory public abstract DirectoryProperty getOutputDirectory()
    The directory to write the scripts into.
    Since:
      9.7.0

  - ### getOutputDir

    @ReplacedBy("outputDirectory") public @Nullable File getOutputDir()
    The directory to write the scripts into.
    Since:
      2.4

  - ### setOutputDir

    public void setOutputDir(@Nullable File outputDir)
    Sets the output dir.
    Since:
      2.4

  - ### getExecutableDir

    @Input public String getExecutableDir()
    The directory to write the scripts into in the distribution.
    Since:
      4.5

  - ### setExecutableDir

    public void setExecutableDir(String executableDir)
    The directory to write the scripts into in the distribution.
    Since:
      4.5

  - ### getMainModule

    @Optional @Input public abstract Property<String> getMainModule()
    The main module name used to start the modular Java application.
    Since:
      6.4

  - ### getMainClass

    @Optional @Input public abstract Property<String> getMainClass()
    The main class name used to start the Java application.
    Since:
      6.4

  - ### getDefaultJvmOpts

    @Optional @Input public @Nullable Iterable<String> getDefaultJvmOpts()
    The application's default JVM options. Defaults to an empty list.
    Since:
      2.4

  - ### setDefaultJvmOpts

    public void setDefaultJvmOpts(@Nullable Iterable<String> defaultJvmOpts)
    Sets the default jvm opts.
    Since:
      2.4

  - ### getApplicationName

    @Input public @Nullable String getApplicationName()
    The application's name.
    Since:
      2.4

  - ### setApplicationName

    public void setApplicationName(@Nullable String applicationName)
    Sets the application name.
    Since:
      2.4

  - ### getGitRef

    @Incubating @Optional @Input public abstract Property<String> getGitRef()
    The Git revision or tag.
    Since:
      9.4.0

  - ### setOptsEnvironmentVar

    public void setOptsEnvironmentVar(@Nullable String optsEnvironmentVar)
    Sets the opts environment var.
    Since:
      2.4

  - ### setExitEnvironmentVar

    @Deprecated public void setExitEnvironmentVar(@Nullable String exitEnvironmentVar)
    Deprecated.
    Sets the exit environment var.
    Since:
      2.4

  - ### getClasspath

    @Classpath @Optional public @Nullable FileCollection getClasspath()
    The class path for the application.
    Since:
      2.4

  - ### getModularity

    public ModularitySpec getModularity()
    Returns the module path handling for executing the main class.
    Since:
      6.4

  - ### setClasspath

    public void setClasspath(@Nullable FileCollection classpath)
    Sets the classpath.
    Since:
      2.4

  - ### getUnixStartScriptGenerator

    public ScriptGenerator getUnixStartScriptGenerator()
    The UNIX-like start script generator.

    Defaults to an implementation of `TemplateBasedScriptGenerator`.

    Since:
      2.4

  - ### setUnixStartScriptGenerator

    public void setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)
    Sets the unix start script generator.
    Since:
      2.4

  - ### getWindowsStartScriptGenerator

    public ScriptGenerator getWindowsStartScriptGenerator()
    The Windows start script generator.

    Defaults to an implementation of `TemplateBasedScriptGenerator`.

    Since:
      2.4

  - ### setWindowsStartScriptGenerator

    public void setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)
    Sets the windows start script generator.
    Since:
      2.4

  - ### generate

    public void generate()
    Generate.
    Since:
      2.4

  - ### getRelativeClasspath

    @Input protected Iterable<String> getRelativeClasspath()
    Returns the relative classpath.
    Since:
      4.4