Detekt — Android Static Code Analysis in Bitbucket PR

Mohanraj
Oct 18, 2020
Photo by Marius Niveri on Unsplash

Hi, in this post I’m going to use the detekt (Static analysis tool) and Bitbucket Checkstyle report pipe to post in results in the Pull Request.

Enable Bitbucket pipeline

Go to the Bitbucket Repository Settings -> Pipelines ->Settings and enable the pipeline

Detekt

Add detekt library to the android project, please refer to the documentation https://detekt.github.io/detekt/ . Please find the configuration which I have used in the module app/build.gradle file,

For the Checkstyle report, the required file format is checkstyle-result.xml, which can be changed. Please refer the checkstyle-report pipe documentation. In this post, I’m using the default report file format.

After performing the Gradle sync, detekt Gradle task will be added to the project.

CI Integration

In the project, add the below file bitbucket-pipelines.yml to the project root folder.

The CI is configured to run when PR is created or updated.

After making all the changes, commit & push the code and Create PR. Wait for the pipeline to complete. Once completed, if issues exist, then comments will be posted in the report section of the PR.

If the Report section is not available in the PR, you might be using the Old PR experience. To use the New PR experience, Click the profile settings icon located at the bottom left corner of the bitbucket page, then select Labs -> New pull request experience and enable the switch.

Thank you for taking the time to read. Please let me know if this was helpful or if you have any questions or see any mistakes or things that could be done even better.

--

--