Gradle plugin
The Contrast Gradle plugin is used to integrate the Contrast.jar with your build. It's capable of authenticating to Contrast, downloading the latest Java agent and verifying your build.
Note
Gradle is a build tool that utilizes
build.gradle
files to configure your applications. It's used to build, package, and test various types of applications.
Clone a sample web application
The easiest way to set up a project is to clone our sample Gradle-based web application. This application has been migrated from Maven to Gradle and relies on MongoDB.
Install and set up the database path.
git clone https://github.com/Contrast-Security-OSS/Contrast-Sample-Gradle-Application brew install mongodb sudo mkdir -p /data/db brew services start mongodb
An application is ready to run. Open the Contrast-Sample-Gradle-Application/build.gradle file. Scroll to find the
contrastConfiguration
extension. You can find all of the values in your personal keys exceptappName
andserverName
.contrastConfiguration { username = "username" apiKey = "apiKey" serviceKey = "serviceKey" apiUrl = "apiUrl" orgUuid = "orgUuid" appName = "editLATER" serverName = "editLATER" }
Install the Contrast JAR file by calling the
contrastInstall
task. This installs the Contrast JAR in the project's build directory.cd path/to/Contrast-Sample-Gradle-Application gradle build -x test contrastInstall
Run the application with the Java agent. The server starts.
cd path/to/Contrast-Sample-Gradle-Application/build java -Dcontrast.agent.java.standalone_app_name=mytestapp -Dcontrast.server=mytestserver -jar libs/Contrast-Sample-Gradle-Application-0.0.1-SNAPSHOT.jar
Check that the application is running at localhost:8080 and that the application shows up in Contrast.
In Contrast, verify that the application with the
appname
specified in the command above shows up.In the Contrast-Sample-Gradle-Application project's build.gradle, edit the
contrastConfiguration
to specify theappName
andserverName
specified as options with the Java agent in the previous step.contrastConfiguration { username = "alreadySetup" apiKey = "alreadySetup" serviceKey = "alreadySetup" apiUrl = "alreadySetup" orgUuid = "alreadySetup" appName = "mytestapp" serverName = "mytestserver" }
Run the verification task at any time to check for vulnerabilities.
gradle build contrastVerify -x test
Use the plugin
The plugin code can be viewed in our GitHub repository. Here you can review the two tasks added by the plugin, contrastInstall
and contrastVerify
, and how they work.
The latest version of the plugin can be found on the Gradle plugin webpage.
Task | Description |
---|---|
| Installs a Contrast Java agent to your local project. The plugin edits the
|
| Checks for new vulnerabilities in your web application. |