Qodana 2024.3 Help

Java, Kotlin, and Groovy

All Qodana linters are based on JetBrains IDEs designed for particular programming languages and frameworks. To analyze Java projects, you can use the following linters:

  • The Qodana for JVM and Qodana for Android linters based on IntelliJ IDEA Ultimate and available under the Ultimate and Ultimate Plus licenses,

  • The Qodana Community for JVM and Qodana Community for Android linters based on IntelliJ IDEA Community Edition and available under the Community license.

To see the list of supported technologies and features, you can navigate to the Supported technologies and features chapter of this section.

Before you start

Before running Qodana, you may need to configure the JDK for your project.

Qodana Cloud

Depending on the specific linter you're using, you may need to obtain a project token that will be used by Qodana for identifying and verifying a license. To do this, follow the steps below:

  1. Navigate to Qodana Cloud and create an account there.

  2. In Qodana Cloud, create an organization, a team, and a project.

  3. On the project card, you can find the project token that you will be using further in this section.

Prepare your software

  1. On the Settings tab of the GitHub UI, create the QODANA_TOKEN encrypted secret and save the project token as its value.

  2. On the Actions tab of the GitHub UI, set up a new workflow and save the following workflow configuration to the .github/workflows/code_quality.yml file:

    name: Qodana on: workflow_dispatch: pull_request: push: branches: - main jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: # Uncomment the linter you wish to use # args: --linter,jetbrains/qodana-jvm:2024.3 # args: --linter,jetbrains/qodana-jvm-community:2024.3 # args: --linter,jetbrains/qodana-jvm-android:2024.3 # args: --linter,jetbrains/qodana-android:2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

    This configuration sample will be modified throughout the section.

  1. In Jenkins, make sure that these plugins are up and running:

    • Docker and Docker Pipeline are required for running Docker images,

    • Git is required for Git operations in Jenkins projects.

    Make sure that Docker is installed and accessible to Jenkins.

    If applicable, make sure that Docker is accessible to the jenkins user as described in the Manage Docker as a non-root user section of the Docker documentation.

  2. In Jenkins, create the qodana-token credential and save the project token as its value.

  3. In Jenkins, create a Multibranch Pipeline project as described on the Jenkins documentation portal.

  1. Make sure that your project repository is accessible to GitLab CI/CD.

  2. In GitLab CI/CD, create the $qodana_token variable and save the project token as its value.

In TeamCity, Create a project and a build configuration.

Install Docker on the machine you are going to run Qodana.

If you are using Linux, you should be able to run Docker under your current non-root user.

Follow the instructions from the Qodana CLI page on GitHub.

Run this command to pull the Docker image of a required linter:

docker pull <linter>

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

Run Qodana

You can run the linters in two modes:

  • Native mode is the recommended method that lets you run linters without using Docker containers,

  • Container mode is an alternative that involves Docker containers.

The qodana.yaml file is a universal method of native mode configuration. Alternatively, you can configure it without using the qodana.yaml file.

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. You can run Qodana using the Qodana Scan GitHub action.

    To inspect the main branch, release branches and the pull requests coming to your repository in native mode, save this workflow configuration to the .github/workflows/code_quality.yml file:

    name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

You can run Qodana using the Qodana Scan GitHub action.

To inspect the main branch, release branches and the pull requests coming to your repository in native mode, save this workflow configuration to the .github/workflows/code_quality.yml file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: args: --ide,<linter-code> env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

More configuration examples are available in the GitHub Actions section.

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. Run this command in the project root directory:

    qodana scan \    -e QODANA_TOKEN="<qodana-cloud-token>"

    If you are using another Qodana Cloud instance than https://qodana.cloud/, override it by declaring the QODANA_ENDPOINT environment variable.

    In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

Run this command in the project root directory:

qodana scan \    -e QODANA_TOKEN="<qodana-cloud-token>" \    --ide <linter-code>

If you are using another Qodana Cloud instance than https://qodana.cloud/, override it by declaring the QODANA_ENDPOINT environment variable.

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

Container mode is available for all linters; however, we recommend that you use native mode whenever possible.

To analyze the main branch, release branches and the pull requests coming to your repository in container mode, save this workflow configuration to the .github/workflows/code_quality.yml file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: # Uncomment the linter that you wish to use # args: --linter,jetbrains/qodana-jvm:2024.3 # args: --linter,jetbrains/qodana-jvm-community:2024.3 # args: --linter,jetbrains/qodana-jvm-android:2024.3 # args: --linter,jetbrains/qodana-android:2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

More configuration examples are available in the GitHub Actions section.

Save this configuration to the Jenkinsfile:

pipeline {   environment {     QODANA_TOKEN=credentials('qodana-token')   }   agent {     docker {       args '''       -v "${WORKSPACE}":/data/project       --entrypoint=""       '''       // Uncomment the linter you would like to employ       // image 'jetbrains/qodana-jvm:2024.3' // Qodana for JVM       // image 'jetbrains/qodana-jvm-community:2024.3' // Qodana Community for JVM       // image 'jetbrains/qodana-jvm-android:2024.3' // Qodana Community for Android       // image 'jetbrains/qodana-android:2024.3' // Qodana for Android     }   }   stages {     stage('Qodana') {       steps {         sh '''qodana'''       }     }   } }

More configuration examples are available in the Jenkins section.

In the root directory of your project, save this snippet to the .gitlab-ci.yml file:

qodana: image: # Uncomment the linter you would like to employ # name: jetbrains/qodana-jvm:2024.3 # Qodana for JVM # name: jetbrains/qodana-jvm-community:2024.3 # Qodana Community for JVM # name: jetbrains/qodana-jvm-android:2024.3 # Qodana Community for Android # name: jetbrains/qodana-android:2024.3 # Qodana for Android entrypoint: [""] cache: - key: qodana-2024.3-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG fallback_keys: - qodana-2024.3-$CI_DEFAULT_BRANCH- - qodana-2024.3- paths: - .qodana/cache variables: QODANA_TOKEN: $qodana_token - script: - qodana --cache-dir=$CI_PROJECT_DIR/.qodana/cache

In this snippet:

  • The cache keyword configures GitLab CI/CD caches to store the Qodana cache, so subsequent runs will be faster,

  • The script keyword runs the qodana command and enumerates the Qodana configuration options described in the Shell commands section,

  • The variables keyword defines the QODANA_TOKEN variable referring to the project token.

More configuration examples are available in the GitLab CI/CD section.

  1. In the TeamCity UI, navigate to the configuration page of a build where you would like to run Qodana.

  2. On the Build Configuration Settings page, navigate to the Build steps page.

  3. On the Build steps page, click the Add build step button.

  4. On the page that opens, select the Qodana runner.

  5. On the New Build Step: Qodana page, click Show advanced options and configure the Qodana runner:

    • Step name uniquely identifies this step among other build steps.

    • Step ID uniquely identifies this step among other build steps.

    • Execute step configures the build condition that will trigger this build step.

    • Working directory sets the directory for the build process, see the TeamCity documentation for details. You can leave this field empty if the Checkout directory parameter is specified on the Version Control Settings tab.

    • Report ID uniquely identifies the report to let you distinguish between multiple reports when several inspection steps are configured within a single build.

    • The Forward reports to TeamCity tests checkbox configures Qodana report availability in the Test tab of the TeamCity UI. Using this option, you can view codebase problems along with other problems detected.

    • Linter configures the Qodana linter.

      Here, select either the Qodana for JVM, Qodana Community for JVM, Qodana Community for Android or the Qodana for Android linter.

    • Version is by default set to Latest.

    • Inspection profile defines an inspection profile:

      • Recommended (default) is one of the default profiles.

      • Embedded profile lets you select a default profile, see the Existing Qodana profiles section for details.

      • Path to the IntelliJ profile lets you specify the path to your custom profile. To use this option, make sure that you also configure the custom profile in the qodana.yaml file.

    • Cloud Token configures a project token generated in Qodana Cloud.

    • Additional Docker arguments configures the arguments accepted by a Docker image, see the Shell commands section for details.

    • Additional Qodana arguments lets you extend the default Qodana functionality, see the Options section for details.

    Configuring the Qodana runner
  6. Click the Save button.

More configuration examples are available in the TeamCity section.

qodana scan \    -e QODANA_TOKEN="<qodana-cloud-token>" \    -l <linter>

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

docker run \    -v <source-directory>/:/data/project/ \    -e QODANA_TOKEN="<cloud-project-token>" \    <linter>

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

If you are using another Qodana Cloud instance than https://qodana.cloud/, override it by declaring the QODANA_ENDPOINT environment variable.

In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

  1. In IntelliJ IDEA Ultimate, navigate to Tools | Qodana | Try Code Analysis with Qodana.

  2. On the Run Qodana dialog, you can configure Qodana.

    Configuring Qodana in the Run Qodana dialog

    This dialog contains the following components:

    Name

    Description

    The qodana.yaml file

    In the text field, you can set up code analysis used by Qodana in this file. You can learn more about available configuration options

    The Send inspection results to Qodana Cloud option

    If you want to send reports to Qodana Cloud, you can check this option and paste the project token generated in Qodana Cloud

    The Save qodana.yaml in project root option

    By checking this option, you can save the Qodana configuration made on this dialog to the qodana.yaml file in the project root of your project

    The Use Qodana analysis baseline option

    Using the baseline feature, you can skip analysis for specific problems

    Click Run for analyzing your code.

  3. On the Server-Side Analysis tab of the Problems tool window, see the inspection results.

Explore analysis results

You can load the latest Qodana report from Qodana Cloud to your IDE as explained below.

  1. In your IDE, navigate to Tools | Qodana | Log in to Qodana.

  2. On the Settings dialog, click Log in.

    Connecting to Qodana Cloud

    This will redirect you to the authentication page.

  3. Select the Qodana Cloud project to link your local project with.

    Linking the project to Qodana Cloud
  4. If you check the Always load most relevant Qodana report option, you will be able to receive the most up-to-date and relevant reports from Qodana Cloud.

    Enabling to load the most relevant reports

    In this case, the IDE will search Qodana Cloud and fetch the report with the revision ID corresponding to the current revision ID (HEAD). If this report is not found, the IDE will select the previous report with the revision ID closest to the current revision ID (HEAD). Otherwise, the IDE retrieves the latest available report from Qodana Cloud.

  5. On the Server-Side Analysis tab of the Problems tool window, you can view the analysis results.

After Qodana analyzed your project and uploaded the analysis results to Qodana Cloud, in Qodana Cloud navigate to your project and review the analysis results report.

Analysis report example

To learn more about Qodana report UI, see the Inspection report section.

Extend Qodana configuration

Adjusting the scope of analysis

Out of the box, Qodana provides two predefined profiles hosted on GitHub:

  • qodana.starter is the default profile and a subset of the more comprehensive qodana.recommended profile.

  • qodana.recommendedis suitable for running in CI/CD pipelines and mostly implements the default IntelliJ IDEA Ultimate profile; see the IntelliJ IDEA Ultimate documentation for details.

You can customize Qodana profiles using configurations in YAML and XML formats. To learn more about configuration basics, visit the Configure Qodana your way section of the documentation.

Enabling the baseline feature

You can skip analysis for specific problems by using the baseline feature. Information about a baseline is contained in a SARIF-formatted file.

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. Save the snippet to the .github/workflows/code_quality.yml file containing the args: --baseline,qodana.sarif.json option that specifies the path to the SARIF-formatted baseline file:

    name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

Save the snippet to the .github/workflows/code_quality.yml file containing the args: --baseline,qodana.sarif.json option that specifies the path to the SARIF-formatted baseline file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - master # The 'master' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: args: --baseline,<path/to/qodana.sarif.json>,--ide,<linter-code> env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. Run this command in the project root directory using the --baseline,<path/to/qodana.sarif.json> option to specify the path to a SARIF-formatted file containing a baseline:

    qodana scan \   -e QODANA_TOKEN="<qodana-cloud-token>" \    --baseline <path/to/qodana.sarif.json>

    In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

Run this command in the project root directory using the --baseline,<path/to/qodana.sarif.json> option to specify the path to a SARIF-formatted file containing a baseline:

qodana scan \    -e QODANA_TOKEN="<cloud-project-token>" \    --ide <linter-code> \    --baseline <path/to/qodana.sarif.json>

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

Save this snippet to the .github/workflows/code_quality.yml file containing the args: --baseline,qodana.sarif.json option that specifies the path to the SARIF-formatted baseline file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - master # The 'master' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: # Uncomment the linter that you wish to use # args: --baseline,<path/to/qodana.sarif.json>,--linter,jetbrains/qodana-jvm:2024.3 # args: --baseline,<path/to/qodana.sarif.json>,--linter,jetbrains/qodana-jvm-community:2024.3 # args: --baseline,<path/to/qodana.sarif.json>,--linter,jetbrains/qodana-jvm-android:2024.3 # args: --baseline,<path/to/qodana.sarif.json>,--linter,jetbrains/qodana-android:2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

In the Jenkinsfile, save the configuration containing the --baseline <path/to/qodana.sarif.json> line that specifies the path to the SARIF-formatted baseline file:

pipeline {   environment {     QODANA_TOKEN=credentials('qodana-token')   }   agent {     docker {       args '''       -v "${WORKSPACE}":/data/project       --entrypoint=""       '''       // Uncomment the linter you would like to employ       // image 'jetbrains/qodana-jvm:2024.3' // Qodana for JVM       // image 'jetbrains/qodana-jvm-community:2024.3' // Qodana Community for JVM       // image 'jetbrains/qodana-jvm-android:2024.3' // Qodana Community for Android       // image 'jetbrains/qodana-android:2024.3' // Qodana for Android     }   }   stages {     stage('Qodana') {       steps {         sh '''         qodana \         --baseline <path/to/qodana.sarif.json>         '''       }     }   } }

In the root directory of your project, save this snippet to the .gitlab-ci.yml file and uncomment the linter that you would like to employ:

qodana: image: # Uncomment the linter you would like to employ # name: jetbrains/qodana-jvm:2024.3 # Qodana for JVM # name: jetbrains/qodana-jvm-community:2024.3 # Qodana Community for JVM # name: jetbrains/qodana-jvm-android:2024.3 # Qodana Community for Android # name: jetbrains/qodana-android:2024.3 # Qodana for Android entrypoint: [""] cache: - key: qodana-2024.3-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG fallback_keys: - qodana-2024.3-$CI_DEFAULT_BRANCH- - qodana-2024.3- paths: - .qodana/cache variables: QODANA_TOKEN: $qodana_token - script: - qodana --baseline <path/to/qodana.sarif.json> --results-dir=$CI_PROJECT_DIR/.qodana/results --cache-dir=$CI_PROJECT_DIR/.qodana/cache

The --baseline <path/to/qodana.sarif.json> line in the script block invokes the baseline feature.

  1. In the TeamCity UI, navigate to the configuration page of a build where you would like to run Qodana.

  2. On the Build Configuration Settings page, navigate to the Build steps page.

  3. On the Build steps page, click the Add build step button.

  4. On the page that opens, select the Qodana runner.

  5. On the New Build Step: Qodana page, click Show advanced options and configure the Qodana runner:

    • Step name uniquely identifies this step among other build steps.

    • Step ID uniquely identifies this step among other build steps.

    • Execute step configures the build condition that will trigger this build step.

    • Working directory sets the directory for the build process, see the TeamCity documentation for details. You can leave this field empty if the Checkout directory parameter is specified on the Version Control Settings tab.

    • Report ID uniquely identifies the report to let you distinguish between multiple reports when several inspection steps are configured within a single build.

    • The Forward reports to TeamCity tests checkbox configures Qodana report availability in the Test tab of the TeamCity UI. Using this option, you can view codebase problems along with other problems detected.

    • Linter configures the Qodana linter.

      Here, select either the Qodana for JVM, Qodana Community for JVM, Qodana Community for Android or the Qodana for Android linter.

    • Version is by default set to Latest.

    • Inspection profile defines an inspection profile:

      • Recommended (default) is one of the default profiles.

      • Embedded profile lets you select a default profile, see the Existing Qodana profiles section for details.

      • Path to the IntelliJ profile lets you specify the path to your custom profile. To use this option, make sure that you also configure the custom profile in the qodana.yaml file.

    • Cloud Token configures a project token generated in Qodana Cloud.

    • Additional Docker arguments configures the arguments accepted by a Docker image, see the Shell commands section for details.

    • Additional Qodana arguments lets you extend the default Qodana functionality, see the Options section for details.

      In this field, specify the baseline feature using the --baseline <path/to/qodana.sarif.json> option.

    Configuring the Qodana runner
  6. Click the Save button.

Choose how you would like to run the baseline feature from the command line:

qodana scan \     -v <path_to_baseline>:/data/base/ \     -e QODANA_TOKEN="<cloud-project-token>" \     -l <linter> \     --baseline /data/base/<path-relative-to-project-dir>/qodana.sarif.json

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

docker run \     -v <source-directory>/:/data/project/ \     -v <path_to_baseline>:/data/base/ \     -e QODANA_TOKEN="<cloud-project-token>" \     <linter> \     --baseline /data/base/<path-relative-to-project-dir>/qodana.sarif.json

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

  1. In your IDE, navigate to the Problems tool window.

  2. In the Problems tool window, click the Server-Side Analysis tab.

  3. On the Server-Side Analysis tab, click the Try Locally button.

  4. On the dialog that opens, expand the Advanced configuration section and specify the path to the baseline file, and then click Run.

Enabling the quality gate

Depending on the linter, you can configure quality gates for:

  • The total number of project problems, available for all linters,

  • Multiple quality gates for problem severities, available for all linters,

  • Code coverage thresholds, available for the Qodana for JVM and Qodana for Android linters.

You can configure quality gates for the total number of project problems, specific problem severities and code coverage by saving this snippet to the qodana.yaml file:

failureConditions:   severityThresholds:     any: 50 # Total number of problems in all severities     critical: 1 # Severities     high: 2     moderate: 3     low: 4     info: 5   testCoverageThresholds:     fresh: 6 # Fresh code coverage     total: 7 # Total percentage

You can configure quality gates for the total number of project problems and specific problem severities by saving this snippet to the qodana.yaml file:

failureConditions:   severityThresholds:     any: 50 # Total number of problems in all severities     critical: 1 # Severities     high: 2     moderate: 3     low: 4     info: 5

Analyzing pull requests

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. The Qodana Scan GitHub action automatically analyzes all pull requests, so you do not have to provide any additional configuration. Save this configuration to the .github/workflows/code_quality.yml file:

    name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

The Qodana Scan GitHub action automatically analyzes all pull requests, so you do not have to provide any additional configuration. Save this configuration to the .github/workflows/code_quality.yml file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - master # The 'master' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: args: --ide,<linter-code> env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

  1. Save the following configuration in the qodana.yaml file:

    • ide: QDJVM for the Qodana for JVM linter,

    • ide: QDJVMC for the Qodana Community for JVM linter.

  2. To analyze changes in your code, employ the --diff-start option and specify a hash of the commit that will act as a base for comparison:

    qodana scan \    -e QODANA_TOKEN="<cloud-project-token>" \    --diff-start=<GIT_START_HASH>

    In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

To analyze changes in your code, employ the --diff-start option and specify a hash of the commit that will act as a base for comparison:

qodana scan \    --ide <linter-code> \    -e QODANA_TOKEN="<cloud-project-token>" \    --diff-start=<GIT_START_HASH>

Here, <linter-code> refers to one of the following linters:

<linter-code> value

Linter

QDJVM

Qodana for JVM

QDJVMC

Qodana Community for JVM

In your browser, open Qodana Cloud to examine the analysis results and reconfigure the analysis. See the Inspection report section of the documentation for full details.

The Qodana Scan GitHub action automatically analyzes all pull requests, so you do not have to provide any additional configuration. Save this configuration to the .github/workflows/code_quality.yml file:

name: Qodana on: workflow_dispatch: pull_request: push: branches: # Specify your branches here - main # The 'main' branch - 'releases/*' # The release branches jobs: qodana: runs-on: ubuntu-latest permissions: contents: write pull-requests: write checks: write steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis - name: 'Qodana Scan' uses: JetBrains/qodana-action@v2024.3 with: # Uncomment the linter you wish to use # args: --linter,jetbrains/qodana-jvm:2024.3,--baseline,<path/to/qodana.sarif.json> # args: --linter,jetbrains/qodana-jvm-community:2024.3,--baseline,<path/to/qodana.sarif.json> # args: --linter,jetbrains/qodana-jvm-android:2024.3,--baseline,<path/to/qodana.sarif.json> # args: --linter,jetbrains/qodana-android:2024.3,--baseline,<path/to/qodana.sarif.json> env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

In the root directory of your project, save the .gitlab-ci.yml file containing the following snippet:

qodana: image: # Uncomment the linter you would like to employ # name: jetbrains/qodana-jvm:2024.3 # Qodana for JVM # name: jetbrains/qodana-jvm-community:2024.3 # Qodana Community for JVM # name: jetbrains/qodana-jvm-android:2024.3 # Qodana Community for Android # name: jetbrains/qodana-android:2024.3 # Qodana for Android entrypoint: [""] cache: - key: qodana-2024.3-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG fallback_keys: - qodana-2024.3-$CI_DEFAULT_BRANCH- - qodana-2024.3- paths: - .qodana/cache variables: QODANA_TOKEN: $qodana_token script: - > qodana --diff-start=$CI_MERGE_REQUEST_TARGET_BRANCH_SHA \ --results-dir=$CI_PROJECT_DIR/.qodana/results \ --cache-dir=$CI_PROJECT_DIR/.qodana/cache artifacts: paths: - .qodana/results expose_as: 'Qodana report'

Here, the --diff-start option specifies a hash of the commit that will act as a base for comparison.

Information about configuring TeamCity for analyzing pull and merge requests is available on the TeamCity documentation portal.

To analyze changes in your code, employ the --diff-start option and specify a hash of the commit that will act as a base for comparison:

qodana scan \    -e QODANA_TOKEN="<cloud-project-token>" \    -l <linter> \    --diff-start=<GIT_START_HASH>

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

docker run \    -v $(pwd):/data/project/ \    -e QODANA_TOKEN="<cloud-project-token>" \    <linter> \    --diff-start=<GIT_START_HASH>

Here, <linter> refers to one of the following linters:

  • jetbrains/qodana-jvm:2024.3

  • jetbrains/qodana-jvm-community:2024.3

  • jetbrains/qodana-jvm-android:2024.3

  • jetbrains/qodana-android:2024.3

Supported technologies and features

Support for

Name

Qodana for JVM and Qodana for Android

Qodana Community for JVM

Qodana Community for Android

Programming languages

Java

Kotlin

Groovy

JavaScript and TypeScript

 

 

Frameworks and libraries

JavaBeans

JUnit

Lombok

TestNG

JPA

Reactive Streams

JavaFX

Java EE

JAX-RS

JSP

Spring

Angular

Node.js

React

Ktor

Micronaut

Quarkus

OpenRewrite

Thymeleaf

Vue

Apache Velocity

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Databases and ORM

Hibernate ORM

MongoDB

Oracle

MySQL

PostgreSQL

SQL

SQL server

Liquibase

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Markup languages

CSS

FreeMarker

HTML

JSON and JSON5

RELAX NG

XML

XPath

XSLT

YAML

TOML

Markdown

Less

SASS/SCSS

PostCSS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Scripting languages

Shell script

Expression Language (EL)

 

 

 

Build management

Ant

Gradle

Maven

Other

Regular expressions

Structural search

Cron

Docker Compose

Dockerfile

GitHub Actions

HTTP Client

Kubernetes

gRPC request scheme

OpenAPI

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Qodana features

Baseline

Quality gate

Code coverage

License audit

Quick-fix

Vulnerability checker

Taint analysis

Only Qodana for JVM

 

 

 

 

 

 

 

 

 

 

Last modified: 11 December 2024