Qodana 2021.2 Help

Docker image configuration

Docker image paths

PathDescription
/data/projectRoot directory of the project to be analyzed
/data/resultsDirectory to store the analysis results, needs to be empty before running Qodana IntelliJ
/root/.config/ideaIntelliJ IDEA configuration directory
/opt/ideaDirectory of the IntelliJ IDEA distributive
/data/profile.xmlUsed if a profile wasn't configured by run options or via qodana.yaml. See Order of resolving a profile.

Configuration options

The following arguments are available for the jetbrains/qodana command.

OptionDescription
-i, --project-dir=Project root folder (default: current working directory /data/project)
-o, --results-dir=Save results to folder (default: /data/results)
-r, --report-dir=Save HTML report to folder (default: /data/results/report)
--cache-dir=Set cache folder (default: /data/cache)
-s, --save-reportGenerate HTML report
-w, --show-reportServe HTML report on port 8080
-b, --baselineRun in baseline mode. Provide the path to an exisitng SARIF report to be used in the baseline state calculation.
--baseline-include-absentInclude in the output report the results from the baseline run that are absent in the current run
--fail-thresholdSet the number of problems that will serve as a quality gate. If this number is reached, the inspection run is terminated.
-dDirectory to be inspected. If not specified, the whole project is inspected by default
-n, --profile-nameName of a profile defined the in project. Note that the name of the profile does not necessarily match the name of the containing file stored in .idea/inspectionProfiles. The actual name is stored as the <option name="myName" value="%profileName%" /> value in the profile xml file and is visible in the IDE UI. For details on working with inspection profiles in the IDE, see the IntelliJ IDEA documentation.
-p, --profile-pathAbsolute path to the profile file
-changesInspect uncommitted changes and report new problems

Examples of execution tuneup

Override the default inspection profile

docker run ... -v <inspection-profile.xml>:/data/profile.xml jetbrains/qodana

If no profile is specified, the default qodana.recommended profile is used. For more options of how to specify a profile, see Order of resolving a profile. For more about available profiles, see Set up a profile.

Save a report as HTML

docker run ... jetbrains/qodana --save-report

By default, the HTML report is stored in a separate report/ subdirectory under the results directory. This location could be configured with --report-dir.

Display a report in HTML

docker run ... -p 8080:8080 jetbrains/qodana --show-report

After the inspection is finished, the container will not exit and will listen on port 8080. You can connect to http://localhost:8080 to see the results. To stop the web server, press Ctrl-C in the Docker console.

Change the Heap size

docker run ... -e _JAVA_OPTIONS=-Xmx6g jetbrains/qodana

By default, Heap size is set to 80% of the host RAM.

Log INFO messages to STDOUT

docker run ... -e IDE_PROPERTIES_PROPERTY='-Didea.log.config.file=info.xml' jetbrains/qodana

The default log level for STDOUT is WARN.

Provide different Gradle settings

docker run ... -v <source-directory>/gradle.properties:/root/.gradle/gradle.properties jetbrains/qodana

Use a different 'idea.properties' file

docker run ... -e IDEA_PROPERTIES=/data/project/idea.properties jetbrains/qodana

Turn off user statistics

To disable the reporting of usage statistics, adjust the idea.headless.enable.statistics value:

docker run ... -e IDE_PROPERTIES_PROPERTY="-Didea.headless.enable.statistics=false" jetbrains/qodana

Manage plugins

The set of plugins depends on the selected Qodana linter.

You can add any free IntellJ platform plugins or your custom plugin by using the following command:

docker run ... -v /your/custom/path/%pluginName%:/opt/idea/plugins/%pluginName% jetbrains/qodana

To optimize the most common cases, some bundled plugins are disabled by default. You can check the whole list of disabled plugins in /root/.config/idea/disabled_plugins.txt.

Java, Kotlin for Server Side, PHP, and their libraries'/frameworks' plugins are enabled by default. Gradle and Maven plugins are also enabled.

To change the plugins list, do any of the following:

  • Override disabled_plugins.txt by mounting your own file:

    docker run ... -v $empty_file$:/root/.config/idea/disabled_plugins.txt jetbrains/qodana
  • Use IDE properties idea.required.plugins.id and idea.suppressed.plugins.id:

    docker run ... -e IDE_PROPERTIES_PROPERTY='-Didea.required.plugins.id=JavaScript,org.intellij.grails' jetbrains/qodana

    or

    docker run ... -e IDE_PROPERTIES_PROPERTY='-Didea.suppressed.plugins.id=com.intellij.spring.security' jetbrains/qodana

Analyze changes

Qodana IntelliJ lets you check only changed files:

docker run -e IDE_PROPERTIES_PROPERTY='-Didea.required.plugins.id=Git4Idea,Subversion,hg4idea' jetbrains/qodana -changes

You can adjust the idea.required.plugins.id value and keep only the VCS plugin suitable for your project.

Run in baseline mode

In baseline run mode, each new Qodana IntelliJ run is compared to some initial run selected as a "baseline". This can help in situations when you have no possibility to fix old problems and rather want to prevent the appearance of new ones.

docker run ... jetbrains/qodana --baseline <baseline-path> [--baseline-include-absent]

where <baseline-path> is the path to a qodana.sarif.json file from an earlier run. If the --baseline-include-absent option is provided, the inspection results will include absent problems, that is the problems detected only in the baseline run but not in the current run.

After the inspection is finished, Qodana IntelliJ displays the summary of the current project state compared to the baseline.

Baseline comparison result - UNCHANGED: 10, NEW: 5, ABSENT: 3

where the detected problems are aggregated as follows:

  • new: The problem was detected only in the current run but not in the baseline run.

  • absent: The problem was detected only in the baseline run but not in the current run.

  • unchanged: The problem was detected both in the current run and in the baseline run.

The SARIF output report will contain the per-problem information on the baseline state.

Set a quality gate

Qodana IntelliJ lets you configure a "quality gate", that is, the number of problems that will act as a threshold. If the threshold number is reached, the inspection run is terminated.

docker run ... jetbrains/qodana --fail-threshold <number>

When running in baseline mode, a threshold is calculated as the sum of new and absent problems. Unchanged results are ignored.

Run as non-root

By default, the container is run as the root user so that Qodana IntelliJ can read any volumes bind-mounted with the project and write the results. As a result, files in the results/ folder are owned by the root after the run. To avoid this, you can run the container as a regular user:

docker run -u $UID ... # or docker run -u $(id -u):$(id -g) ...

Note that in this case the results/ folder on host should already be created and owned by you. Otherwise, Docker will create it as root and Qodana IntelliJ will not be able to write to it.

Cache dependencies

You can decrease the time for a Qodana IntelliJ run by persisting cache from one run to another. For example, package and dependency management tools such as Maven, Gradle, npm, and Yarn keep a local cache of downloaded dependencies.

By default, Qodana IntelliJ would save caches to folder /data/cache inside container. This location could be changed via --cache-dir cli argument. The data inside is per-repository, so you can pass cache from branch-a to build checking branch-b. In this case, only new dependencies would be downloaded, if they were added.

Example for local run:

docker run --rm -it -p 8080:8080 \ -v <source-directory>/:/data/project/ \ -v <output-directory>/:/data/results/ \ -v <cache-directory>/:/data/cache/ \ jetbrains/qodana --show-report

In this case mapping the same <cache-directory> would speed up the second run.

In a GitHub workflow you can utilise actions/cache, see full example.

GitLab CI also has cache which can be stored only inside the project directory. In this case, we recommend excluding the cache folder from inspection via qodana.yaml.

Order of resolving a profile

Qodana IntelliJ checks the configuration parameters for resolving the inspection profile in this order:

  1. Profile with the name %name% from the command-line option --profile-name %name%.

  2. Profile by the path %path% from the command-line option --profile-path %path%.

  3. Profile with the name %name% from qodana.yaml.

  4. Profile by the path %path% from qodana.yaml.

  5. Profile mounted to /data/profile.xml.

  6. Fall back to using the default qodana.recommended profile.

Last modified: 18 October 2021