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:
java.lang.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()
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:
applicationName
optsEnvironmentVar
exitEnvironmentVar
mainModule
mainClass
executableDir
defaultJvmOpts
appNameSystemProperty
appHomeRelativePath
classpath
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 Deprecated Methods 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).protected org.gradle.internal.jvm.JavaModuleDetector
getJavaModuleDetector()
Property<java.lang.String>
getMainClass()
The main class name used to start the Java application.java.lang.String
getMainClassName()
Deprecated.Property<java.lang.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()
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)
Deprecated.void
setOptsEnvironmentVar(java.lang.String optsEnvironmentVar)
void
setOutputDir(java.io.File outputDir)
void
setUnixStartScriptGenerator(ScriptGenerator unixStartScriptGenerator)
void
setWindowsStartScriptGenerator(ScriptGenerator windowsStartScriptGenerator)
-
Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMapping
-
Methods inherited from class org.gradle.api.DefaultTask
compareTo, 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, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService
-
Methods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
-
-
-
Method Detail
-
getObjectFactory
@Inject protected ObjectFactory getObjectFactory()
-
getJavaModuleDetector
@Inject protected org.gradle.internal.jvm.JavaModuleDetector getJavaModuleDetector()
-
getOptsEnvironmentVar
@Nullable @Optional @Input public java.lang.String getOptsEnvironmentVar()
The environment variable to use to provide additional options to the JVM.
-
getExitEnvironmentVar
@Nullable @Optional @Input public java.lang.String getExitEnvironmentVar()
The environment variable to use to control exit value (Windows only).
-
getUnixScript
@Internal public java.io.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 java.io.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 java.io.File getOutputDir()
The directory to write the scripts into.
-
setOutputDir
public void setOutputDir(@Nullable java.io.File outputDir)
-
getExecutableDir
@Input public java.lang.String getExecutableDir()
The directory to write the scripts into in the distribution.- Since:
- 4.5
-
setExecutableDir
public void setExecutableDir(java.lang.String executableDir)
The directory to write the scripts into in the distribution.- Since:
- 4.5
-
getMainModule
@Optional @Input public Property<java.lang.String> getMainModule()
The main module name used to start the modular Java application.- Since:
- 6.4
-
getMainClass
@Optional @Input public Property<java.lang.String> getMainClass()
The main class name used to start the Java application.- Since:
- 6.4
-
getMainClassName
@Input @Optional @Nullable @Deprecated public java.lang.String getMainClassName()
Deprecated.The main class name used to start the Java application.
-
setMainClassName
@Deprecated public void setMainClassName(@Nullable java.lang.String mainClassName)
Deprecated.
-
getDefaultJvmOpts
@Nullable @Optional @Input public java.lang.Iterable<java.lang.String> getDefaultJvmOpts()
The application's default JVM options. Defaults to an empty list.
-
setDefaultJvmOpts
public void setDefaultJvmOpts(@Nullable java.lang.Iterable<java.lang.String> defaultJvmOpts)
-
getApplicationName
@Nullable @Input public java.lang.String getApplicationName()
The application's name.
-
setApplicationName
public void setApplicationName(@Nullable java.lang.String applicationName)
-
setOptsEnvironmentVar
public void setOptsEnvironmentVar(@Nullable java.lang.String optsEnvironmentVar)
-
setExitEnvironmentVar
public void setExitEnvironmentVar(@Nullable java.lang.String exitEnvironmentVar)
-
getClasspath
@Nullable @Classpath @Optional public FileCollection getClasspath()
The class path for the application.
-
getModularity
public ModularitySpec getModularity()
Returns the module path handling for executing the main class.- Since:
- 6.4
-
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()
-
getRelativeClasspath
@Input protected java.lang.Iterable<java.lang.String> getRelativeClasspath()
-
-