Enabling javac debugging for Apache ANT

2019-03-12 05:08发布

问题:

Just a simple question. For ANT builds, if I leave the the debuglevel parameter completely out will it compile with ALL debugging information? Or would it be better to include debuglevel="lines,vars,source" in javac task? I want to enable the maximum level of debugging possible. Here's a snippet:

<javac srcdir="${dir.source}"
     destdir="${dir.classes}"
     deprecation="${javac.deprecation}"
     debug="${veracode.release.mode}"
     debuglevel="lines,vars,source" <-- should I leave this line out? -->
     optimize="${javac.optimize}">

回答1:

Short answer: Yes, you may leave the debuglevel attribute out as long as you set the debug attribute to true.

From the javac Ant task documentation:

debug

Indicates whether source should be compiled with debug information; defaults to off. If set to off, -g:none will be passed on the command line for compilers that support it (for other compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.

debugLevel

Keyword list to be appended to the -g command-line switch. This will be ignored by all implementations except modern, classic(ver >= 1.2) and jikes. Legal values are none or a comma-separated list of the following keywords: lines, vars, and source. If debuglevel is not specified, by default, nothing will be appended to -g. If debug is not turned on, this attribute will be ignored.

Therefore, setting debug to true and omitting debugLevel is the same as passing the flag -g with no options appended. According to the javac documentation, passing the -g flag with nothing appended is equivalent to specifying sources, lines, and vars.