CreateStartScripts
public class CreateStartScripts
extends org.gradle.api.internal.ConventionTask
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()
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(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') }
Task.Namer
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
Constructor | Description |
---|---|
CreateStartScripts() |
Modifier and Type | Method | Description |
---|---|---|
void |
generate() |
|
java.lang.String |
getApplicationName() |
The application's name.
|
FileCollection |
getClasspath() |
The class path for the application.
|
java.lang.Iterable<java.lang.String> |
getDefaultJvmOpts() |
The application's default JVM options.
|
java.lang.String |
getExecutableDir() |
The directory to write the scripts into in the distribution.
|
java.lang.String |
getExitEnvironmentVar() |
The environment variable to use to control exit value (Windows only).
|
java.lang.String |
getMainClassName() |
The main classname used to start the Java application.
|
java.lang.String |
getOptsEnvironmentVar() |
The environment variable to use to provide additional options to the JVM.
|
java.io.File |
getOutputDir() |
The directory to write the scripts into.
|
protected java.lang.Iterable<java.lang.String> |
getRelativeClasspath() |
|
java.io.File |
getUnixScript() |
Returns the full path to the Unix script.
|
ScriptGenerator |
getUnixStartScriptGenerator() |
The UNIX-like start script generator.
|
java.io.File |
getWindowsScript() |
Returns the full path to the Windows script.
|
ScriptGenerator |
getWindowsStartScriptGenerator() |
The Windows start script generator.
|
void |
setApplicationName(java.lang.String applicationName) |
|
void |
setClasspath(FileCollection classpath) |
|
void |
setDefaultJvmOpts(java.lang.Iterable<java.lang.String> defaultJvmOpts) |
|
void |
setExecutableDir(java.lang.String executableDir) |
The directory to write the scripts into in the distribution.
|
void |
setExitEnvironmentVar(java.lang.String exitEnvironmentVar) |
|
void |
setMainClassName(java.lang.String mainClassName) |
|
void |
setOptsEnvironmentVar(java.lang.String optsEnvironmentVar) |
|
void |
setOutputDir(java.io.File outputDir) |
|
void |
setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator) |
|
void |
setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator) |
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
conventionMapping, conventionMapping, getConventionMapping
newInputDirectory, newInputFile, newOutputDirectory, newOutputFile
@Nullable @Optional @Input public java.lang.String getOptsEnvironmentVar()
@Nullable @Optional @Input public java.lang.String getExitEnvironmentVar()
@Internal public java.io.File getUnixScript()
@Internal public java.io.File getWindowsScript()
@OutputDirectory @Nullable public java.io.File getOutputDir()
public void setOutputDir(@Nullable java.io.File outputDir)
@Incubating @Input public java.lang.String getExecutableDir()
@Incubating public void setExecutableDir(java.lang.String executableDir)
@Input @Nullable public java.lang.String getMainClassName()
public void setMainClassName(@Nullable java.lang.String mainClassName)
@Nullable @Optional @Input public java.lang.Iterable<java.lang.String> getDefaultJvmOpts()
public void setDefaultJvmOpts(@Nullable java.lang.Iterable<java.lang.String> defaultJvmOpts)
@Nullable @Input public java.lang.String getApplicationName()
public void setApplicationName(@Nullable java.lang.String applicationName)
public void setOptsEnvironmentVar(@Nullable java.lang.String optsEnvironmentVar)
public void setExitEnvironmentVar(@Nullable java.lang.String exitEnvironmentVar)
@Internal @Nullable public FileCollection getClasspath()
public void setClasspath(@Nullable FileCollection classpath)
@Internal public ScriptGenerator getUnixStartScriptGenerator()
Defaults to an implementation of TemplateBasedScriptGenerator
.
public void setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)
@Internal public ScriptGenerator getWindowsStartScriptGenerator()
Defaults to an implementation of TemplateBasedScriptGenerator
.
public void setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)
public void generate()
@Input protected java.lang.Iterable<java.lang.String> getRelativeClasspath()