Mix SonarQube

Mix utilities for the sonar-elixir SonarQube plugin.

CIHex.pmLicenseLast Updated

[!NOTE] Mix tasks in this package are meant to be run before sonar-scanner to support features like test coverage reporting. You also need the sonar-elixir plugin installed in your SonarQube instance for Elixir language support.

Installation

Add sonarqube to your list of dependencies and configure it as the cover tool in mix.exs:

def project do
  [
    app: :your_app,
    deps: deps(),
    version: "0.1.0",
    # Add this.
    test_coverage: [tool: SonarQube.Coverage]
  ]
end

# Add this so `mix sonarqube.coverage` runs in the test environment.
def cli do
  [preferred_envs: ["sonarqube.coverage": :test]]
end

def deps do
  [
    {:sonarqube, "~> 0.1.0", only: [:dev, :test], runtime: false}
  ]
end

Usage

Run tests with coverage and generate a SonarQube-compatible XML report:

mix sonarqube.coverage

This produces cover/sonar-coverage.xml alongside the standard Elixir coverage output. All arguments are passed through to mix test:

mix sonarqube.coverage test/my_module_test.exs

Options

Options are configured via test_coverage in mix.exs:

Option Default Description
:sonar_xmlcover/sonar-coverage.xml Output path for the XML report
test_coverage: [tool: SonarQube.Coverage, sonar_xml: "reports/sonar-coverage.xml"]

SonarQube Configuration

Add the coverage report path to your sonar-project.properties:

sonar.coverageReportPaths=cover/sonar-coverage.xml

Then run sonar-scanner to upload the results to your SonarQube instance.

License

Copyright (c) 2026 Henry Popp

This project is MIT licensed. See the LICENSE for details.