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:

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')
 }
 
  • Constructor Details

    • CreateStartScripts

      public CreateStartScripts()
  • Method Details

    • getObjectFactory

      @Inject protected abstract ObjectFactory getObjectFactory()
    • getJavaModuleDetector

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

      @Optional @Input public Property<String> getOptsEnvironmentVar()
      The environment variable to use to provide additional options to the JVM.
    • 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).
    • getUnixScript

      @Internal public RegularFileProperty 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. TODO: This should be Provider[RegularFile], but we don't support such upgrade with @ReplacesEagerProperty
    • getWindowsScript

      @Internal public RegularFileProperty 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. TODO: This should be Provider[RegularFile], but we don't support such upgrade with @ReplacesEagerProperty
    • getOutputDir

      @OutputDirectory public DirectoryProperty getOutputDir()
      The directory to write the scripts into.
    • getExecutableDir

      @Input public Property<String> getExecutableDir()
      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 abstract ListProperty<String> getDefaultJvmOpts()
      The application's default JVM options. Defaults to an empty list.
    • getApplicationName

      @Input @Optional public Property<String> getApplicationName()
      The application's name.
    • getGitRef

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

      @Deprecated public void setExitEnvironmentVar(@Nullable String exitEnvironmentVar)
      Deprecated.
    • getClasspath

      @Classpath @Optional public abstract ConfigurableFileCollection getClasspath()
      The class path for the application.
    • getModularity

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

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

      Defaults to an implementation of TemplateBasedScriptGenerator.

    • setUnixStartScriptGenerator

      public void setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)
    • getWindowsStartScriptGenerator

      public ScriptGenerator getWindowsStartScriptGenerator()
      The Windows start script generator.

      Defaults to an implementation of TemplateBasedScriptGenerator.

    • setWindowsStartScriptGenerator

      public void setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)
    • generate

      public void generate()
    • getRelativeClasspath

      @Input protected Iterable<String> getRelativeClasspath()
      TODO: Remove with Gradle 9, we anyway track classpath via getClasspath(), this looks unnecessary