Skip to content

Instantly share code, notes, and snippets.

@loeschzwerg
Last active August 20, 2020 13:40
Show Gist options
  • Save loeschzwerg/0d4210f75abc375a9aa52753be2ce7bf to your computer and use it in GitHub Desktop.
Save loeschzwerg/0d4210f75abc375a9aa52753be2ce7bf to your computer and use it in GitHub Desktop.
Setting up SonarQube for Clojure

Sonarqube for Clojure

Setup

Pull a sonarqube docker image from DockerHub and run it.

docker pull sonarqube
docker run -d --name sonarqube -p 9000:9000 sonarqube

Get the latest sonar-clojure-plugin.jar from github and add it to sonarqube as a plugin.

wget https://github.com/fsantiag/sonar-clojure/releases/download/v2.0.0/sonar-clojure-plugin-2.0.0.jar
docker cp sonar-clojure-plugin-2.0.0.jar sonarqube:/opt/sonarqube/extensions/plugins/

Restart the docker container to rerun it with sonar-clojure plugin enabled.

docker restart sonarqube

Open localhost:9090 and login with {:user admin :pw admin}. Now add a new project and remember the Project Key for later. Generate a token (you won't actually need it, when running local), select language Other -> OS and add the scanner:

sonar-scanner

Get sonar-scanner and put it on your $PATH.

Run

altered from sonar-clojure
  1. Change your project.clj file and add the required plugins:

    :plugins [[jonase/eastwood "0.3.6"]
                [lein-kibit "0.1.8"]
                [lein-ancient "0.6.15"]
                [lein-cloverage "1.1.2"]
                [lein-nvd "1.4.0"]]
    
  2. Create a sonar-project.properties file in the root folder of your app:

    sonar.projectKey=your-project-key
    sonar.projectName=YourProjectName
    sonar.projectVersion=1.0
    sonar.sources=.
    
  3. Run sonar-scanner on your project. You may also run the plugins by themselves to make sure they actually run (e.g. lein kibit or lein nvd check), or if you want an altered output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment