Commonly used compiler options can be added to 'makeprg' by setting the
b/g:javac_makeprg_params variable. For example: >
let g:javac_makeprg_params = "-Xlint:all -encoding utf-8"
MAVEN *compiler-maven*
Commonly used compiler options can be added to 'makeprg' by setting the
b/g:maven_makeprg_params variable. For example: >
let g:maven_makeprg_params = "-DskipTests -U -X"
SPOTBUGS *compiler-spotbugs*
SpotBugs is a static analysis tool that can be used to find bugs in Java.
It scans the Java bytecode of all classes in the currently open buffer.
(Therefore, `:compiler! spotbugs` is not supported.)
Commonly used compiler options can be added to 'makeprg' by setting the
"b:" or "g:spotbugs_makeprg_params" variable. For example: >vim
let b:spotbugs_makeprg_params = "-longBugCodes -effort:max -low"
The global default is "-workHard -experimental".
By default, the class files are searched in the directory where the source
files are placed. However, typical Java projects use distinct directories
for source files and class files. To make both known to SpotBugs, assign
their paths (distinct and relative to their common root directory) to the
following properties (using the example of a common Maven project): >vim
let g:spotbugs_properties = {
\ 'sourceDirPath': ['src/main/java'],
\ 'classDirPath': ['target/classes'],
\ 'testSourceDirPath': ['src/test/java'],
\ 'testClassDirPath': ['target/test-classes'],
\ }
Note that source and class path entries are expected to come in pairs: define
both "sourceDirPath" and "classDirPath" when you are considering at least one,
and apply the same logic to "testSourceDirPath" and "testClassDirPath".
Note that values for the path keys describe only for SpotBugs where to look
for files; refer to the documentation for particular compiler plugins for more
information.
The default pre- and post-compiler actions are provided for Ant, Maven, and
Javac compiler plugins and can be selected by assigning the name of a compiler
plugin (`ant`, `maven`, or `javac`) to the "compiler" key: >vim
let g:spotbugs_properties = {
\ 'compiler': 'maven',
\ }
This single setting is essentially equivalent to all the settings below, with
the exception made for the "PreCompilerAction" and "PreCompilerTestAction"
values: their listed |Funcref|s will obtain no-op implementations whereas the
implicit Funcrefs of the "compiler" key will obtain the requested defaults if
available. >vim
let g:spotbugs_properties = {
\ 'PreCompilerAction':
\ function('spotbugs#DefaultPreCompilerAction'),
\ 'PreCompilerTestAction':
\ function('spotbugs#DefaultPreCompilerTestAction'),
\ 'PostCompilerAction':
\ function('spotbugs#DefaultPostCompilerAction'),
\ 'sourceDirPath': ['src/main/java'],
\ 'classDirPath': ['target/classes'],
\ 'testSourceDirPath': ['src/test/java'],
\ 'testClassDirPath': ['target/test-classes'],
\ }
With default actions, the compiler of choice will attempt to rebuild the class
files for the buffer (and possibly for the whole project) as soon as a Java
syntax file is loaded; then, `spotbugs` will attempt to analyze the quality of
the compilation unit of the buffer.
Vim commands proficient in 'makeprg' [0] can be composed with default actions.
Begin by considering which of the supported keys, "DefaultPreCompilerCommand",
"DefaultPreCompilerTestCommand", or "DefaultPostCompilerCommand", you need to
write an implementation for, observing that each of these keys corresponds to
a particular "*Action" key. Follow it by defining a new function that always
declares an only parameter of type string and puts to use a command equivalent
of |:make|, and assigning its |Funcref| to the selected key. For example:
>vim
function! GenericPostCompilerCommand(arguments) abort
execute 'make ' . a:arguments
endfunction
let g:spotbugs_properties = {
\ 'DefaultPostCompilerCommand':
\ function('GenericPostCompilerCommand'),
\ }
When "PostCompilerAction" is available, "PostCompilerActionExecutor"