-
Notifications
You must be signed in to change notification settings - Fork 7
Usage
This is the usage manual for DCD (Dead Code Detector).

Note that analysis of directories of classes is faster than analysis of jar or war files, because there is no need to uncompress and so less IO on disk. So if you are really concerned about the duration, directories of classes is the preferred choice.
You can launch the UI offline with a java command :
- Download the file dcd.zip from releases.
- Extract the zip file in a directory
- Extract the zip file in a directory and open a command prompt there
- Launch java with the command
java -cp dcd.jar;src/main/lib/* dcd.ui.DeadCodeDetectorUI(on linux or unix, replace ";" with ":") - In the window, provide a directory (or list of directories, or jar or war files) containing classes to analyze. Note : You can use drag and drop of directories and files to do that.
- Then choose the type(s) of dead code to detect (private+package-private and/or protected+public and/or local and/or init). Warning if you try the public type : Public dead code analysis is useless for libraries with a public api for unknown applications. For applications with public type checked, remember to add all users of classes, including libraries, and to add classes filters for these libraries otherwise you will have a lot of false positives.
- Optionally, you can also click the "Advanced" button to specify classes and methods/fields filters with regular expressions or an xml report file.
- And finally click the "Detect dead code". Note: Parameters will be saved for the next time.
Optionally if you have multiple configurations, you can add to the java command an application argument with the path and name of a properties file like the one described in the next paragraph.
You can launch DCD in text mode with a java command :
- Download the file dcd.zip from releases.
- Extract the zip file in a directory and open a command prompt there
- Launch java with the command "java -cp dcd.jar;lib/* dcd.DeadCodeDetector c:/myProject/dcdConfig.properties" (on linux or unix, replace ";" with ":")
- Where "c:/myProject/dcdConfig.properties" is the path and name of a properties file which contains parameters values like this sample configuration :
#directory, or list of directories, containing classes to analyze
directories = ./classes,\
./lib/mylib.jar
#[optional] regexp, or list of regexp, of classes to exclude (ex : mypackage.*)
excludedClasses = mylib.*
#[optional] regexp, or list of regexp, of methods or fields to exclude (ex : get.*)
excludedMethods =
#[optional] detect private and package-private dead code (true by default)
privateDeadCode = true
#[optional] detect also public and protected dead code (false by default)
publicDeadCode = false
#[optional] detect also dead local variables (and self assignments and toString on String, false by default)
localDeadCode = false
#[optional] detect also useless initializations (false by default)
initDeadCode = false
#[optional] report to a file in xml format and not to standard output (standard output and no xml by default)
#On Windows, use '/' in place of '\' which is an escape character
xmlReportFile =
You can launch DCD from an ant script like in the following one:
<project basedir=".">
<target name="dcd">
<java dir="." classname="dcd.DeadCodeDetector" fork="true" timeout="600000"
maxmemory="128m" failonerror="true">
<classpath>
<pathelement location="dcd.jar" />
<fileset dir="src/main/lib" includes="*.jar" />
</classpath>
<arg file="dcdConfig.properties" />
</java>
</target>
</project>
Where "dcdConfig.properties" is the path and name of a properties file which contains parameters values like the sample configuration in the previous paragraph.
By default, a report in text format is written in the output of ant. A report in a XML file is available by writing xmlReportFile = <path to>/dcd.xml in the "dcdConfig.properties" file.