Class 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
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:
applicationNameoptsEnvironmentVarexitEnvironmentVarmainClassNamedefaultJvmOptsappNameSystemPropertyappHomeRelativePathclasspath
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 Task
Task.Namer -
Field Summary
Fields inherited from interface Task
TASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate()The application's name.The class path for the application.The application's default JVM options.The environment variable to use to control exit value (Windows only).The main classname used to start the Java application.The environment variable to use to provide additional options to the JVM.The directory to write the scripts into.Returns the full path to the Unix script.The UNIX-like start script generator.Returns the full path to the Windows script.The Windows start script generator.voidsetApplicationName(String applicationName) voidsetClasspath(FileCollection classpath) voidsetDefaultJvmOpts(Iterable<String> defaultJvmOpts) 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, getConventionMappingMethods inherited from class DefaultTask
newInputDirectory, newInputFile, newOutputDirectory, newOutputFileMethods inherited from class org.gradle.api.internal.AbstractTask
addValidator, appendParallelSafeAction, compareTo, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, doFirst, doFirst, doFirst, doLast, doLast, doLast, execute, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExecuter, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTemporaryDir, getTemporaryDirFactory, getValidators, hasProperty, injectIntoNewInstance, isEnabled, isHasCustomActions, leftShift, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setExecuter, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString
-
Constructor Details
-
CreateStartScripts
public CreateStartScripts()
-
-
Method Details
-
getOptsEnvironmentVar
-
getExitEnvironmentVar
-
getUnixScript
-
getWindowsScript
-
getOutputDir
The directory to write the scripts into. -
setOutputDir
-
getMainClassName
-
setMainClassName
-
getDefaultJvmOpts
-
setDefaultJvmOpts
-
getApplicationName
-
setApplicationName
-
setOptsEnvironmentVar
-
setExitEnvironmentVar
-
getClasspath
The class path for the application. -
setClasspath
-
getUnixStartScriptGenerator
The UNIX-like start script generator.Defaults to an implementation of
TemplateBasedScriptGenerator. -
setUnixStartScriptGenerator
-
getWindowsStartScriptGenerator
The Windows start script generator.Defaults to an implementation of
TemplateBasedScriptGenerator. -
setWindowsStartScriptGenerator
-
generate
public void generate() -
getRelativeClasspath
-