Skip to content

Continuous integration

Updated on 5 December 2026

The plugin adds a command, stau-metro, that the launcher of IntelliJ IDEA runs instead of the IDE: it opens a project, calculates the metrics of a profile, writes them to files and ends with an exit code. With it, a build can fail when the code goes beyond the thresholds, and keep the reports of every run.

What it needs

  • IntelliJ IDEA 2026.2 or later with Stau Metro installed in its plugins directory. On a continuous integration machine, unzipping the plugin ZIP into that directory is enough (“Installation”).
  • The JVM option -Djava.awt.headless=true. The IDE starts without a user interface by itself only for its own commands, such as inspect. Without the option it starts with windows, which a machine without a display cannot show. Set it in the variable JAVA_TOOL_OPTIONS=-Djava.awt.headless=true, or add the line to the .vmoptions file of the IDE.
  • No IDE open with the same configuration directory. A continuous integration machine has its own. On your machine, close the IDE, or point the IDEA_PROPERTIES variable at an idea.properties file with other directories in idea.config.path, idea.system.path, idea.plugins.path and idea.log.path, as the “GitHub Actions example” does.

Running the command

idea.sh stau-metro <project> [options]                                   # Linux
idea64.exe stau-metro <project> [options]                                # Windows
"/Applications/IntelliJ IDEA.app/Contents/MacOS/idea" stau-metro <project> [options]   # macOS

For example, to measure the app module with the complexity profile and write an HTML report and a CSV:

JAVA_TOOL_OPTIONS=-Djava.awt.headless=true idea.sh stau-metro ~/src/shop \
  --profile complexity --scope module:app \
  --output build/metrics/metrics.html --output build/metrics/metrics.csv

Options

Option Meaning Default
<project> The project directory: an IntelliJ IDEA project, a Gradle build or a Maven project required
--profile <profile> An included profile, an IDE profile or a profile file (“The profile”) quick-health-check
--scope <scope> project, module:<name> or directory:<path>, with the path relative to the project directory project
--output <file> A file to write; it can be repeated. The extension decides the format: .csv, .xml, .html (or .htm), .sarif, .sonar.json or .met, a snapshot none
--format <format> csv, xml, html, sarif, sonar or snapshot, for a single --output with another extension from the extension
--baseline <file.met> A snapshot to compare with: only the values that got worse than in it fail none
--fail-on-warnings Values beyond a warning threshold fail too, not only those beyond an error threshold off
-h, --help Prints the usage

An option takes its value as the next argument or after =: --scope=module:app. Relative paths of files are resolved against the current directory. When in doubt, use absolute paths.

The files are the same that Export Results... writes with Everything, and the CSV uses the default options: a comma, no BOM and the line of identifiers (“Exporting the results”). The command does not write Stau Metro JSON.

The profile

--profile looks for the profile in this order:

  1. A file, if the value ends in .xml or has a path separator.
  2. An included profile by its identifier: quick-health-check, complexity, lines-of-code, dependencies, junit-testing, javadoc-coverage, martin-packaging, chidamber-kemerer, mood, kotlin-idioms, class-count or file-count.
  3. An IDE profile by its exact name, among those of the configuration directory of the IDE that runs the command.
  4. An included profile by its name in English or in Spanish, in any case: Complexity metrics.

For the job to use the profile of your team, keep it in the repository as a file: write it with Export..., in Metrics Profiles..., and pass its path. A project profile, from .idea/stau-metro-profiles.xml, is not found by its name: export it as well. The file can also be written by hand (“File formats”):

<METRICS_PROFILE name="CI gate">
  <METRIC metricId="method.cc" enabled="true" warnAbove="10" errorAbove="20" />
  <METRIC metricId="class.wmc" enabled="true" />
</METRICS_PROFILE>

A metric without its own thresholds takes the reference ones, as in the IDE, and the metrics the file does not name are not calculated.

Exit codes

Code Meaning
0 No value fails
1 Without --baseline: a value is beyond an error threshold, or a warning threshold with --fail-on-warnings
2 With --baseline: a value is beyond a threshold it was not beyond in the baseline
3 A usage or execution error: a wrong argument; a project, profile, module, directory or baseline that cannot be found or read; a profile without enabled metrics; a run without values; a file that cannot be written

The metrics that fail, in whole or in part, are reported as in the Summary, but they do not change the exit code.

Adopting it on a project that already goes beyond thresholds

On a project with a history, many values usually go beyond a threshold already, and a build that always fails is not much use. There are two ways to fail only on what is new, and they can be combined.

The accepted hot spots of the project

If the project has a baseline, .idea/stau-metro-baseline.xml, the command always reads it: a value covered by an acceptance does not fail and does not count as a hot spot, and the report says how many values were accepted. A value worse than the one accepted is judged as any other. The file is part of the project, is created from the IDE and is reviewed in the pull requests like the code (“Accepted hot spots and baseline”).

A baseline snapshot

With --baseline, the command compares with a snapshot instead of looking at the thresholds alone:

  • A value that was already beyond a threshold in the baseline does not fail, however much it grows.
  • A value that goes beyond a higher threshold than in the baseline fails with code 2: from within the thresholds to an error, or from a warning to an error, and also to a warning with --fail-on-warnings.
  • Both runs are judged with the thresholds of the profile of this one, and elements are matched by their name: a renamed or moved one is new.
  • A metric the baseline has no values of is not compared, and the command says which.

Write the baseline on the main branch with --output baseline.met, or with Save Snapshot... in the IDE. Unlike the baseline of the project, the snapshot travels with the continuous integration job, not with the code.

What it writes

  • To the standard output: the scope, the profile, the global line of the Summary, the failing values, worst first and at most 50, the files written and the result, such as Result: no value fails (exit code 0).
  • To the standard error: the progress, the warnings of the baseline and the metrics that failed or are partial.

The texts are in the language of the plugin. With a new configuration directory, as on a continuous integration machine, the language is Automatic (IDE language), which is usually English.

Every file of --output is written before the exit code is decided, so a build that fails still has its reports.

Import and indexing

Nothing has to be prepared before the command. It opens the project as the inspect command of the IDE does: if it has no .idea, it imports it; it lets the Gradle and Maven support of the IDE import the build, and waits for every configuration activity to end. A Gradle build that is still not imported, as in a fresh checkout, is imported by the command, which says so on the standard error and waits for it. A failed import ends with code 3. Last, it waits for the indexing to end before it measures anything.

  • A Gradle or Maven build needs a JDK to import with (JAVA_HOME) and the network access its dependencies ask for.
  • Keeping the idea.system.path directory between runs, in a cache, saves most of the indexing time.
  • When the project closes, the IDE stores its .idea/workspace.xml, and an imported build leaves the .idea directory that the import creates, as inspect does.

A GitHub Actions job

This job measures the repository on every push and pull request, and keeps the reports:

name: Code metrics

on: [push, pull_request]

jobs:
  metrics:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    env:
      IDEA_VERSION: "2026.2.3"
      STAU_METRO_ZIP: https://metro.stau.me/download/stau-metro-0.1.2.zip
    steps:
      - uses: actions/checkout@v7

      # The JDK that the Gradle or Maven import uses
      - uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: 21

      - name: Install IntelliJ IDEA and Stau Metro
        run: |
          curl -fsSL -o idea.tar.gz "https://download.jetbrains.com/idea/idea-${IDEA_VERSION}.tar.gz"
          mkdir -p "$RUNNER_TEMP/idea" "$RUNNER_TEMP/ide/plugins"
          tar -xzf idea.tar.gz -C "$RUNNER_TEMP/idea" --strip-components=1
          curl -fsSL -o stau-metro.zip "$STAU_METRO_ZIP"
          unzip -q stau-metro.zip -d "$RUNNER_TEMP/ide/plugins"
          {
            echo "idea.config.path=$RUNNER_TEMP/ide/config"
            echo "idea.system.path=$RUNNER_TEMP/ide/system"
            echo "idea.plugins.path=$RUNNER_TEMP/ide/plugins"
            echo "idea.log.path=$RUNNER_TEMP/ide/log"
          } > "$RUNNER_TEMP/idea.properties"

      - name: Calculate the metrics
        env:
          IDEA_PROPERTIES: ${{ runner.temp }}/idea.properties
          JAVA_TOOL_OPTIONS: -Djava.awt.headless=true
        run: |
          "$RUNNER_TEMP/idea/bin/idea.sh" stau-metro "$GITHUB_WORKSPACE" \
            --profile "$GITHUB_WORKSPACE/config/metrics-profile.xml" \
            --baseline "$GITHUB_WORKSPACE/config/metrics-baseline.met" \
            --output "$GITHUB_WORKSPACE/build/metrics/metrics.html" \
            --output "$GITHUB_WORKSPACE/build/metrics/metrics.csv" \
            --output "$GITHUB_WORKSPACE/build/metrics/metrics.met"

      - name: Keep the reports
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: metrics
          path: build/metrics/

Replace the profile and baseline paths with yours. Without --profile the command uses quick-health-check, and without --baseline it fails on any value beyond an error threshold.

Hot spots in GitHub code scanning

With --output <file>.sarif, the command writes the hot spots in SARIF, and GitHub shows them as code scanning alerts and as annotations of the pull requests: each metric beyond a threshold is an alert, an error or a warning, at the lines of its method, class or interface. The paths are relative to the project directory, so measure the root of the repository, $GITHUB_WORKSPACE.

Give the job the permission to write security events, write the SARIF file and upload it:

jobs:
  metrics:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      security-events: write
    steps:
      # ... checkout, JDK, IntelliJ IDEA and Stau Metro, as above

      - name: Calculate the metrics
        env:
          IDEA_PROPERTIES: ${{ runner.temp }}/idea.properties
          JAVA_TOOL_OPTIONS: -Djava.awt.headless=true
        run: |
          "$RUNNER_TEMP/idea/bin/idea.sh" stau-metro "$GITHUB_WORKSPACE" \
            --profile "$GITHUB_WORKSPACE/config/metrics-profile.xml" \
            --output "$GITHUB_WORKSPACE/build/metrics/metrics.sarif" \
            --output "$GITHUB_WORKSPACE/build/metrics/metrics.html"

      - name: Upload the hot spots to code scanning
        if: always()
        uses: github/codeql-action/upload-sarif@v4
        with:
          sarif_file: build/metrics/metrics.sarif
          category: stau-metro

if: always() uploads the alerts also when the command fails the build on a threshold.

Hot spots in SonarQube

Write --output build/metrics/metrics.sonar.json and pass it to the analysis:

sonar-scanner -Dsonar.externalIssuesReportPaths=build/metrics/metrics.sonar.json

or set sonar.externalIssuesReportPaths in sonar-project.properties, or in the property of the same name of the SonarQube plugin for Gradle or Maven. The base directory of the analysis has to be that of the project Stau Metro measured. SonarQube shows only the issues of the files it analyses.

Both formats are described in “File formats”.