Skip to content
This documentation applies to Codacy Self-hosted v3.4.0

For the latest updates and improvements, see the latest Cloud documentation instead.

Running SpotBugs

To run SpotBugs as a client-side tool:

  1. Enable Run analysis through build server in your repository Settings, tab General, Repository analysis.

    This setting enables Codacy to wait for the results of the local analysis before resuming the analysis of your commits.

    Run analysis through build server

  2. Obtain a project API Token for your repository.

    You need the project API Token to allow the Codacy Analysis CLI to authenticate to Codacy when reporting the analysis results.

  3. Set the following environment variable to specify your project API Token:

    export CODACY_PROJECT_TOKEN=<your project API Token>
    

    Warning

    Never write API tokens on your configuration files and keep your API tokens well protected, as they grant owner permissions to your projects.

    We recommend that you set API tokens as environment variables. Check the documentation of your CI/CD platform on how to do this.

  4. If you are using Codacy Self-hosted set the following environment variable to specify your Codacy instance URL:

    export CODACY_API_BASE_URL=<your Codacy instance URL>
    
  5. Compile your Java or Scala repository on your build server, as you would normally do.

  6. Download and run the Codacy Analysis CLI on the root of the repository, specifying the tool SpotBugs.

    codacy-analysis-cli analyze --tool spotbugs \
                                --allow-network \
                                --upload \
                                --verbose
    

The Codacy Analysis CLI runs SpotBugs on the compiled classes of your repository and uploads the results to Codacy so you can use them in your workflow.

Detecting sources and compiled classes

The Codacy Analysis CLI tries to find the compiled classes and map results to the source files automatically. If you use Maven, Gradle, or sbt the Codacy Analysis CLI also detects the default layouts automatically.

If there is an issue with detection, you can configure these paths manually by adding a .codacy.yml Codacy configuration file to the root of the repository:

---
engines:
  spotbugs:
    modules:
      - classesDirectories: [ "core/target/classes" ]
        sourceDirectories:  [ "core/src/main" ]
      - classesDirectories: [ "api/target/classes" ]
        sourceDirectories:  [ "api/src/main" ]

Increasing the timeout to run SpotBugs

When running SpotBugs on the compiled classes of larger projects, the default execution timeout of 15 minutes may not be enough for SpotBugs to complete the analysis.

To increase the timeout that SpotBugs has to execute, use the option --tool-timeout when running the Codacy Analysis CLI. For example, use --tool-timeout 1hour to set the timeout to one hour.

Share your feedback 📢

Did this page help you?

Thanks for the feedback! Is there anything else you'd like to tell us about this page?

We're sorry to hear that. Please let us know what we can improve:

Alternatively, you can create a more detailed issue on our GitHub repository.

Thanks for helping improve the Codacy documentation.

If you have a question or need help please contact support@codacy.com.

Last modified February 27, 2021