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,ExtensionAware,Task,org.gradle.util.Configurable<Task>
- Direct Known Subclasses:
CreateStartScripts
public class CreateStartScripts extends org.gradle.api.internal.ConventionTaskCreates 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()andgetUnixStartScriptGenerator()properties, of typeScriptGenerator.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 theTemplateBasedScriptGenerator.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:
applicationNameoptsEnvironmentVarexitEnvironmentVarmainClassNameexecutableDirdefaultJvmOptsappNameSystemPropertyappHomeRelativePathclasspath
Example:
task createStartScripts(type: CreateStartScripts) { unixStartScriptGenerator.template = resources.text.fromFile('customUnixStartScript.txt') windowsStartScriptGenerator.template = resources.text.fromFile('customWindowsStartScript.txt') }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gradle.api.Task
Task.Namer
-
-
Field Summary
-
Fields inherited from interface org.gradle.api.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()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidgenerate()StringgetApplicationName()The application's name.FileCollectiongetClasspath()The class path for the application.Iterable<String>getDefaultJvmOpts()The application's default JVM options.StringgetExecutableDir()The directory to write the scripts into in the distribution.StringgetExitEnvironmentVar()The environment variable to use to control exit value (Windows only).StringgetMainClassName()The main classname used to start the Java application.StringgetOptsEnvironmentVar()The environment variable to use to provide additional options to the JVM.FilegetOutputDir()The directory to write the scripts into.protected Iterable<String>getRelativeClasspath()FilegetUnixScript()Returns the full path to the Unix script.ScriptGeneratorgetUnixStartScriptGenerator()The UNIX-like start script generator.FilegetWindowsScript()Returns the full path to the Windows script.ScriptGeneratorgetWindowsStartScriptGenerator()The Windows start script generator.voidsetApplicationName(String applicationName)voidsetClasspath(FileCollection classpath)voidsetDefaultJvmOpts(Iterable<String> defaultJvmOpts)voidsetExecutableDir(String executableDir)The directory to write the scripts into in the distribution.voidsetExitEnvironmentVar(String exitEnvironmentVar)voidsetMainClassName(String mainClassName)voidsetOptsEnvironmentVar(String optsEnvironmentVar)voidsetOutputDir(File outputDir)voidsetUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)voidsetWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)-
Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMapping
-
Methods inherited from class org.gradle.api.DefaultTask
newInputDirectory, newInputFile, newOutputDirectory, newOutputFile
-
Methods inherited from class org.gradle.api.internal.AbstractTask
appendParallelSafeAction, compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTaskIdentity, getTemporaryDir, getTemporaryDirFactory, getTimeout, hasProperty, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, replaceLogger, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString
-
-
-
-
Method Detail
-
getOptsEnvironmentVar
@Nullable @Optional @Input public String getOptsEnvironmentVar()
The environment variable to use to provide additional options to the JVM.
-
getExitEnvironmentVar
@Nullable @Optional @Input public String getExitEnvironmentVar()
The environment variable to use to control exit value (Windows only).
-
getUnixScript
@Internal 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.
-
getWindowsScript
@Internal 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.
-
getOutputDir
@OutputDirectory @Nullable public File getOutputDir()
The directory to write the scripts into.
-
getExecutableDir
@Incubating @Input public String getExecutableDir()
The directory to write the scripts into in the distribution.- Since:
- 4.5
-
setExecutableDir
@Incubating public void setExecutableDir(String executableDir)
The directory to write the scripts into in the distribution.- Since:
- 4.5
-
getMainClassName
@Input @Nullable public String getMainClassName()
The main classname used to start the Java application.
-
getDefaultJvmOpts
@Nullable @Optional @Input public Iterable<String> getDefaultJvmOpts()
The application's default JVM options. Defaults to an empty list.
-
getClasspath
@Internal @Nullable public FileCollection getClasspath()
The class path for the application.
-
setClasspath
public void setClasspath(@Nullable FileCollection classpath)
-
getUnixStartScriptGenerator
@Internal public ScriptGenerator getUnixStartScriptGenerator()
The UNIX-like start script generator.Defaults to an implementation of
TemplateBasedScriptGenerator.
-
setUnixStartScriptGenerator
public void setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)
-
getWindowsStartScriptGenerator
@Internal public ScriptGenerator getWindowsStartScriptGenerator()
The Windows start script generator.Defaults to an implementation of
TemplateBasedScriptGenerator.
-
setWindowsStartScriptGenerator
public void setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)
-
generate
public void generate()
-
-