The plugin provides tasks required for analyzing & reporting defects in Java code using Coverity.
- Clone the repository
- Run gradlew jar
- Copy build/libs/coverityplugin-.jar to your favorite artifact repo
buildscript {
repositories {
url //Path to local artifact
}
dependencies {
classpath 'naedward.gradle:coverityplugin:0.7.0'
}
}
apply plugin: 'coverity'
To use the Coverity plugin, copy the coverityplugin-xxx.jar to lib/plugins directory under the root project. Then, add the following in your root project's build script:
apply plugin: 'clover'
buildscript {
repositories {
flatDir { dirs rootProject.projectDir.toString() + '/lib/plugins' }
}
dependencies {
classpath ':coverityplugin-0.5.0'
}
}
Coverity tasks can be configured using coverity extension. Typical usage will be:
coverity {
intermediateDir = file("${buildDir}/coverity")
coverityHome = System.getProperty("COVERITY_HOME")
covConnectHost = System.getProperty("COVERITY_HOST")
covConnectDataPort = System.getProperty("COVERITY_PORT")
covConnectUser = System.getProperty("COVERITY_USER")
covConnectPassword = System.getProperty("COVERITY_PASSWORD")
commitDefectsStreamName = System.getProperty("COVERITY_STREAM_NAME")
}
Alternatively, the Coverity Connect details can be specified using a configuration file too:
coverity {
intermediateDir = file("${buildDir}/coverity")
coverityHome = System.getProperty("COVERITY_HOME")
commitDefectsXmlConfig = file("/absolute/path/to/config/file")
commitDefectsStreamName = System.getProperty("COVERITY_STREAM_NAME")
}
A sample XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverity SYSTEM "coverity_config.dtd">
<coverity>
<config>
<cim>
<host>coverity.example.com</host>
<client_security>
<user>my-user</user>
<password>myPassword</password>
</client_security>
<commit>
<port>9090</port>
</commit>
</cim>
</config>
</coverity>
If the Coverity plugin is applied in the root project, it'll recurse through all the sub-projects & include the sources
and libraries while executing coverity-emit-java command. If you want to apply Coverity only to selected sub-projects,
apply the plugin to those projects & disable including sub-projects:
coverity {
...
includeSubProjects = false
...
}
Before running the analysis tasks, remember to run compileJava task as covEmit task expects the .class files to be present.
The Coverity plugin defines the following tasks:
covEmit: Runscov-emit-javaCoverity commandcovAnalyze: Runscov-analyze-javaCoverity command. This depends oncovEmittask.covCommit: Runscov-commit-defectsCoverity command. This depends oncovAnalyzetask.covManageEmit: Manages intermediate directory.covClean: DeletesintermediateDirdirectory.
Coverity Gradle Plugin can be configured by passing a closure to coverity extension.
intermediateDir: The directory, where all the coverity files will be written. Defaults tointDircommitDefectsStreamName: The stream name to be used while committing the defects to Coverity Connect.commitDefectsXmlConfig: The configuration file containing the details of Coverity Connect.excludes: Specify regex pattern to exclude files from being analyzed. Defaults to""(empty string).includeTestSource: Specifies whether test sources should be analyzed by Coverity.includeTestSource: Specifies whether test sources should be analyzed by Coverity. Defaults tofalse.includeAutogenSource: Specifies whether source files underautogendirectories should be analyzed by Coverity. Defaults tofalse.includeSubProjects: Specifies whether to recursively include source & library files from sub-projects. Defaults totrue.coverityHome: The location of cov-analysis installation. If cov-analysis/bin directory is in the PATH, this can be left null.bootClasspath: The bootclasspath to be used duringcov-emit-java. If the default models included in coverity is enough, leave this null.covConnectHost: The hostname/IP Address of Coverity Connect server. Used only ifcommitDefectsXmlConfigisn't specified.covConnectDataPort: The datport of Coverity Connect server. Used only ifcommitDefectsXmlConfigisn't specified.covConnectUser: The username in Coverity Connect server. Used only ifcommitDefectsXmlConfigisn't specified.covConnectPassword: The password ofcovConnectUserin Coverity Connect server. Used only ifcommitDefectsXmlConfigisn't specified.analyzeNumWorkers: Number of worker threads to use when using analyze task. Defaults toauto. Note: VM's have issues with --auto