Home

Awesome

Gradle Qodana Plugin

official JetBrains project Gradle Plugin Portal Build GitHub Discussions Twitter Follow

Gradle interface to run code inspections from IntelliJ IDEA.

Important: This project requires Gradle 6.6 or newer, however it is recommended to use the latest Gradle available. Update it with:

./gradlew wrapper --gradle-version=VERSION

Issue Tracker

All the issues, feature requests, and support related to the Gradle Qodana Plugin is handled on YouTrack.

If you'd like to file a new issue, please use the following YouTrack | New Issue link.

Docker Image with Qodana tool

Docker Hub: https://hub.docker.com/r/jetbrains/qodana-jvm-community

Gradle Qodana Configuration

Note: Make sure you have docker already installed and available in your environment.

Apply Gradle plugin org.jetbrains.qodana in Gradle configuration file:

Note: The latest version is: Gradle Plugin Portal

qodana { } extension configuration

Properties available for configuration in the qodana { } top level configuration closure:

NameDescriptionTypeDefault Value
autoUpdateAutomatically pull the latest Docker image before running the inspection.Booleantrue
baselinePathRun in baseline mode. Provide the path to an existing SARIF report to be used in the baseline state calculation.Stringnull
baselineIncludeAbsentInclude in the output report the results from the baseline run that are absent in the current run.Booleanfalse
cachePathPath to the cache directory.Stringnull
dockerContainerNameName of the Qodana Docker container.Stringidea-inspections
dockerImageNameName of the Qodana Docker image.Stringjetbrains/qodana-jvm-community:latest
executableDocker executable name.Stringdocker
projectPathPath to the project folder to inspect.Stringproject.projectDir
failThresholdA number of problems that will serve as a quality gate. If this number is reached, the inspection run is terminated.Int10000
resultsPathPath to directory to store results of the task.String"${projectPath}/build/results"
reportPathPath to the directory to store the generated report.String"${projectPath}/build/results/report"
saveReportGenerate HTML report.Booleanfalse
showReportServe an HTML report on showReportPort port.Booleanfalse
showReportPortDefault port used to show an HTML report.Int8080

Gradle Qodana Tasks

runInspections

Starts Qodana Inspections in a Docker container.

Task relies on the qodana { } extension configuration, however it provides also additional properties and helper methods to configure the Docker image.

Properties

NameDescriptionTypeDefault Value
disabledPluginsPathPath to the list of plugins to be disabled in the Qodana IDE instance to be mounted as /root/.config/idea/disabled_plugins.txt.Stringnull
changesInspect uncommitted changes and report new problems.Booleanfalse
jvmParametersJVM parameters to start IDEA JVM.List<String>empty
profilePathPath to the profile file to be mounted as /data/profile.xml.Stringnull

Helper methods

NameDescription
bind(outerPort: Int, dockerPort: Int)Adds new port binding.
mount(outerPath: String, dockerPath: String)Mounts local directory to the given Docker path.
env(name: String, value: String)Adds an environment variable.
dockerArg(argument: String)Adds a Docker argument to the executed command.
arg(argument: String)Adds a Docker image argument to the executed command.

updateInspections

Pulls the latest Qodana Inspections Docker container.

Task will be run automatically before the runInspections if the qodana.autoUpdate property will be set to true.

stopInspections

Stops the Qodana Inspections Docker container.

cleanInspections

Cleans up the Qodana Inspections output directory.

Example

Add this to your Gradle configuration file:

Note: Docker requires at least 4GB of memory. Set it in Docker Preferences > Resources > Memory section.

Now you can run inspections with runInspections Gradle task:

gradle runInspections 
// or
./gradlew runInspections

Full guide for options and configuration parameters could be found on qodana docs page.

Build Locally

Build

Execute Gradle task publishToMavenLocal to build Gradle Qodana Plugin and publish it into local Maven repository. By default, plugin will be published into ~/.mvn/org/jetbrains/qodana/ directory.

Apply

Add Maven local repository into available repositories in your Gradle project. For this you need to add following lines at the beginning of settings.gradle[.kts] file:

pluginManagement {
    repositories {
        mavenLocal()
        gradlePluginPortal()
    }
}

Apply Gradle Qodana Plugin with snapshot version in Gradle configuration file and mount the Maven Local directory: