Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, ExtensionAware, Task, Configurable<Task>CreateStartScripts@DisableCachingByDefault(because="Not worth caching") public class CreateStartScripts extends org.gradle.api.internal.ConventionTask
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(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:
applicationNameoptsEnvironmentVarexitEnvironmentVarmainModulemainClassexecutableDirdefaultJvmOptsappNameSystemPropertyappHomeRelativePathclasspathExample:
task createStartScripts(type: CreateStartScripts) {
unixStartScriptGenerator.template = resources.text.fromFile('customUnixStartScript.txt')
windowsStartScriptGenerator.template = resources.text.fromFile('customWindowsStartScript.txt')
}
Task.NamerTASK_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() |
|
String |
getApplicationName() |
The application's name.
|
FileCollection |
getClasspath() |
The class path for the application.
|
Iterable<String> |
getDefaultJvmOpts() |
The application's default JVM options.
|
String |
getExecutableDir() |
The directory to write the scripts into in the distribution.
|
String |
getExitEnvironmentVar() |
The environment variable to use to control exit value (Windows only).
|
protected org.gradle.internal.jvm.JavaModuleDetector |
getJavaModuleDetector() |
|
Property<String> |
getMainClass() |
The main class name used to start the Java application.
|
String |
getMainClassName() |
Deprecated.
|
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 ObjectFactory |
getObjectFactory() |
|
String |
getOptsEnvironmentVar() |
The environment variable to use to provide additional options to the JVM.
|
File |
getOutputDir() |
The directory to write the scripts into.
|
protected Iterable<String> |
getRelativeClasspath() |
|
File |
getUnixScript() |
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.
|
ScriptGenerator |
getWindowsStartScriptGenerator() |
The Windows start script generator.
|
void |
setApplicationName(String applicationName) |
|
void |
setClasspath(FileCollection classpath) |
|
void |
setDefaultJvmOpts(Iterable<String> defaultJvmOpts) |
|
void |
setExecutableDir(String executableDir) |
The directory to write the scripts into in the distribution.
|
void |
setExitEnvironmentVar(String exitEnvironmentVar) |
|
void |
setMainClassName(String mainClassName) |
Deprecated.
|
void |
setOptsEnvironmentVar(String optsEnvironmentVar) |
|
void |
setOutputDir(File outputDir) |
|
void |
setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator) |
|
void |
setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator) |
conventionMapping, conventionMapping, getConventionMappingcompareTo, 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, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceappendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getOnlyIf, getReasonNotToTrackState, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, prependParallelSafeAction, setImpliesSubProjectsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdoNotTrackState, getConvention@Inject protected ObjectFactory getObjectFactory()
@Inject protected org.gradle.internal.jvm.JavaModuleDetector getJavaModuleDetector()
@Nullable @Optional @Input public String getOptsEnvironmentVar()
@Nullable @Optional @Input public String getExitEnvironmentVar()
@Internal public File getUnixScript()
@Internal public File getWindowsScript()
@OutputDirectory @Nullable public File getOutputDir()
@Input public String getExecutableDir()
public void setExecutableDir(String executableDir)
@Optional @Input public Property<String> getMainModule()
@Optional @Input public Property<String> getMainClass()
getMainClassName() and setMainClassName(String).@ReplacedBy("mainClass") @Nullable @Deprecated public String getMainClassName()
@Deprecated public void setMainClassName(@Nullable String mainClassName)
@Nullable @Optional @Input public Iterable<String> getDefaultJvmOpts()
@Nullable @Classpath @Optional public FileCollection getClasspath()
public ModularitySpec getModularity()
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()