Getting started with Klocwork Desktop Java Plug-in for IntelliJ IDEA

Getting started with Klocwork Desktop Java Plug-in for IntelliJ IDEA

The Klocwork plug-in for IntelliJ IDEA helps you detect and fix issues before check-in.

Connect to a project on the Klocwork Server

You get the most from static code analysis when you connect a small local project to a larger project on the Klocwork Server. The small local project is analyzed quickly while incorporating Klocwork knowledge bases generated on the server where additional source files were analyzed (for example, shared libraries). Connecting to a server project also allows you to share issue status information with the integration build analysis and among team members. You can run a standalone desktop analysis, but the analysis only derives knowledge from the local project's source files.

You perform this step only once for each project.

  1. In IntelliJ IDEA, click File > Settings.
  2. Under Other Settings or IDE Settings (depending on your version), select Klocwork Settings.
  3. Fill in your Klocwork Server and License Server information and click Apply.
    Note: Enable the Use secure connection checkbox if a secure connection to the Klocwork Server has been set up.
  4. Under Project settings, select Klocwork Static Analysis.
  5. In the Klocwork project menu, select your project and configure other options as you choose.
  6. Click Apply to finalize your changes.

Analyze your code

  1. In IDEA, open the project you want to analyze.
  2. Click in the toolbar.
    Tip: The analysis button in the toolbar always analyzes modules that you've selected on the Klocwork for Java Project Settings page. By contrast, using the right-click Run Klocwork for Java analysis menu option analyzes modules that are currently selected in the Project Explorer (whether or not they are selected on the Project Settings page).

When the analysis is complete, the Klocwork for Java view shows the analysis results.

Investigate detected issues

In the Klocwork for Java view:

  1. Click an issue in the list to view the source code where the issue appears.
  2. Use Traceback information to investigate the issue. Traceback lines link to events that contributed to the issue. Key statements that contribute to issues are marked with red rectangles and include a description of the problem.
  3. Get help on an issue by right-clicking the issue and selecting Show help.

Fix defects and ignore the rest

For a real defect:

  1. Fix the issue in your code and save your changes.
  2. Run the analysis by clicking .
    If the issue disappears from the list, it's fixed.

For an issue that doesn't need to be fixed:

  1. Right-click the issue in the list and select Change Status > Ignore.
  2. Enter a comment and click OK.

If you're connected to a project on the Klocwork Server, your changes are now visible to other developers, and in Klocwork Static Code Analysis. Your desktop project is also updated with any changes made by other developers. This happens even before another integration build analysis has been run.