Compile Java source files using the javac
command.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.jdk.javac.ext |
Category: | Compiling tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory GeneratorTaskFactory ProcessTaskFactory |
See also: | Jdk6JavacTF |
Description:
Use the javac
program to compile Java source files.
The following strategy is used for searching for the javac
program to use:
- Use the value of the javacExecutable property, if set
- Use the file
bin/javac[.exe]
relative to the javaHome property, if set - Use the file
bin/javac[.exe]
relative to theJAVA_HOME
environment variable, if set - Search for
javac[.exe]
in the directories listed in thePATH
environment variable.
If a property is not set, javac
's default value is used.
Required properties
Properties
annotationProcessingMode | top |
Set the mode for annotation processing.
This corresponds
to javac
's -proc
option.
- Setter method:
setAnnotationProcessingMode(JavacAnnotationProcessingMode m)
parameters:m
– The annotation processing mode.
annotationProcessor | top |
A list of fully qualified class names of the annotation
processors to use. This corresponds to javac
's
-processor
option.
- Setter method:
addAnnotationProcessor(String n)
Add one annotation processor class.parameters:n
– The fully qualified name of an annotation processor class.- Setter method:
addAnnotationProcessors(Object o)
Add one or several annotation processor classes.parameters:o
– One or an array or collection of fully qualified class names of annotation processors (strings).- Setter method:
clearAnnotationProcessors()
Clear the list of annotation processors.
annotationProcessorOptions | top |
Annotation processor options.
Corresponds to
javac
's -A
option.
- Setter method:
addAnnotationProcessorOption(String key, String value)
Add one annotation processor option.parameters:key
– The option name.value
– The option value.- Setter method:
addAnnotationProcessorOptions(Map<String, String> m)
Add all annotation processor options from aparameters:Map
.m
– The option map.- Setter method:
clearAnnotationProcessorOptions()
Clear the list of annotation processor options.
annotationProcessorPath | top |
A path where annotation processors can be found.
This
corresponds to javac
's -processorpath
option.
- Setter method:
setAnnotationProcessorPath(Object o)
parameters:
arguments | top |
Arguments (options) to the compiler. See the
javac
documentation for the compiler version used for a list of
accepted values. The arguments are given to the compiler in the order that they
were added.
- Setter method:
addArgument(String s)
Add one compiler option.parameters:s
– Ajavac
option.- Setter method:
addArguments(Object o)
Add one or several compiler options.parameters:o
– One compiler option or an array or collection of compiler options (strings).- Setter method:
clearArguments()
Clear the list of compiler options.
classpathDecorators | top |
A collection of
PathDecorator:s that are used
to add entries to the classpath. The decorators are run in the order that they
are added to this property. Classpath decorator entries are added to the classpath after all entries added
manually to the classpathEntries
property.
- Setter method:
addClasspathDecorator(PathDecorator pd)
Add one classpath decorator to the end of the list.parameters:pd
– A classpath decorator.- Setter method:
addClasspathDecorators(Object o)
Add one or several classpath decorators.parameters:- Setter method:
clearClasspathDecorators()
Clear the list of classpath decorators.- See also:
- classpathEntries
classpathEntries | top |
Manually set classpath entries. An entry must be a Jar file or a class file directory.
- Setter method:
addClasspathEntries(Object o)
Add one or several classpath entries.parameters:o
– One or an array or collection of entries to add to the class path.
Interpreted byInterpretAsFileStrategy
.- Setter method:
addClasspathEntry(Object o)
Add one entry to the end of the class path.parameters:- Setter method:
clearClasspathEntries()
Clear the list of classpath entries.- See also:
- classpathDecorators
debugOptions | top |
This option decides what debug information to include in the compiled classes. Set it to JavacDebugKeyword.ALL to include all debug information.
This corresponds to javac
's -g
option.
- Setter method:
addDebugOption(JavacDebugKeyword o)
Add one debug option.parameters:o
– The debug option.- Setter method:
addDebugOptions(Object o)
Add one debug option or an array or collection of debug options.parameters:- Setter method:
clearDebugOptions()
Clear the list of debug options.- Default value:
- Not set (use
javac
's default).
deprecation | top |
Should detailed deprecation information be displayed?
This
corresponds to javac
's -deprecation
flag.
- Setter method:
setDeprecation(boolean b)
parameters:b
– Should detailed deprecation information be displayed?
encoding | top |
The name of the character encoding of the source files.
- Setter method:
setEncoding(String s)
parameters:s
– The name of the encoding, e.g.UTF-8
.- Default value:
- The platform's default character encoding.
environmentVariables | top |
Environment variables for the program. By default, the variables set are added
to the environment of the Schmant script. See the
inheritEnvironmentVariables
property.
- Setter method:
addEnvironmentVariable(String name, String value)
parameters:name
– The environment variable name, for instancePATH
.value
– The value of the variable.- Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.parameters:o
– A string or an array or collection of strings. Each string must have the formatNAME=VALUE
.- Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.- See also:
- inheritEnvironmentVariables
failOnErrors | top |
If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.
- Setter method:
setFailOnErrors(boolean b)
parameters:b
– Should the task fail on errors?- Default value:
-
true
(fails on errors)
implicitClassFileGeneration | top |
Should class files be generated for implicitly loaded source files?
This corresponds to javac
's -implicit
option.
- Setter method:
setImplicitClassFileGeneration(JavacImplicitClassFileGeneration j)
parameters:j
– Should class files for implicitly loaded source files be generated?- Default value:
false
(implicit class files are not generated).
inheritEnvironmentVariables | top |
Should the environment variables of the Schmant script be inherited?
- Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:b
– Should environment variables be inherited?- Default value:
true
(environment variables are inherited)- See also:
- environmentVariables
javacExecutable | top |
The javac
program to use for compiling Java
files.
- Setter method:
setJavacExecutable(Object o)
parameters:- See also:
- javaHome
javaHome | top |
The location of the Java Runtime Environment or Java Development Kit to use
- Setter method:
setJavaHome(Object o)
parameters:- See also:
- javacExecutable
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
noWarn | top |
Should warning messages from javac
be
disabled? This corresponds to javac
's -nowarn
flag.
- Setter method:
setNoWarn(boolean b)
parameters:b
– Disable warnings?
overwriteStrategy | top |
The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.
If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.
Non-empty directories are never overwritten, regardless of the chosen strategy.
- Setter method:
setOverwrite(boolean b)
Setting this to a value ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.b
– Should an existing entity be overwritten?- Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.parameters:strat
– The overwrite strategy.- Default value:
- DontOverwriteAndThrowException
- See also:
- target
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sourceCodeVersion | top |
The source code version accepted.
- Setter method:
setSourceCodeVersion(String release)
parameters:release
– The source code version accepted. See thejavac
documentation for the compiler version used for a list of accepted values.
sourceFiles | top |
A collection of Java files to compile.
If this is set, only these source files will be compiled. If this is not set, all source files under the sources directories will be compiled.
- Setter method:
addSourceFile(Object o)
Add one or several source files.parameters:- Setter method:
addSourceFiles(Object o)
Add one or several source files.parameters:- Default value:
- Not set (compile all source files in the source directories).
- See also:
- sources
sourceFilesDir | top |
The directory where generated source files will be put.
This corresponds to javac
's -s
option.
- Setter method:
setSourceFilesDir(Object o)
parameters:
sources (required) | top |
The source directories for Java files.
- Setter method:
addSource(Object o)
Add one or several source paths.parameters:- Setter method:
addSources(Object o)
Add one or several source paths.parameters:- Setter method:
clearSources()
Discard all source paths.- Setter method:
setSource(Object o)
Set one or several source paths, discarding previously set paths.parameters:- Setter method:
setSources(Object o)
Set one or several source paths, discarding previously set paths.parameters:- See also:
- sourceFiles
stderrStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stderr
.
- Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:s
– Thestderr
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.SEVERE
- See also:
- stdoutStrategy
stdoutStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stdout
.
- Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:s
– Thestdout
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.INFO
- See also:
- stderrStrategy
target (required) | top |
The target directory to put compiled classes in.
- Setter method:
setTarget(Object o)
parameters:- See also:
- overwriteStrategy
targetVersion | top |
The target Java version for generated class files. The class files will only run on the targeted and later versions of Java.
- Setter method:
setTargetVersion(String version)
parameters:version
– The target Java version for generated class files. See thejavac
documentation for the compiler version used for a list of accepted values.
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
workingDirectory | top |
The working directory for the program. (The directory that the program is started in.)
- Setter method:
setWorkingDirectory(Object o)
parameters:- Default value:
- The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.
Examples
Example 1
Compile source files in the directory hierarchy under
src
. Put the class files in a directory hierarchy under
bin
.
JavaScript
Example 2
Compile all source files with names that don't end in
_test.java
from src
and put the class files in
bin
.
JavaScript
JRuby
* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.