Skip to content

How to build and test plugin on local

Daniel Mühlbachler-Pietrzykowski edited this page Oct 30, 2021 · 10 revisions

Requirements: 64 bit OS. 32 bit will end instantly with no error to be found.

  1. Launch Sonar in Docker

if already run sonar in docker: docker start sonarqube-8.9.3-community (you can recheck it by docker container ls -all)

if no sonarqube container(USE THIS): docker pull sonarqube:8.9.3-community Run: docker run -d --name sonarqube-8.9.3-community -p 9000:9000 -p 9092:9092 sonarqube:8.9.3-community

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES
0258089f3c31        sonarqube           "./bin/run.sh"      3 minutes ago       Up 3 minutes        0.0.0.0:9000->9000/tcp, 0.0.0.0:9092->9092/tcp   sonarqub

1.1) Log into http://localhost:9000/admin/marketplace?search=checkstyle (admin/admin) and install checkstyle . Do restart.

1.2) After restart create new profile , make is default, activate all checks that are changed in new checkstyle release.

1.3) do validation of code by mvn sonar:sonar. It is better to have some violations from activated rules.

  1. build upgraded to new checkstyle plugin and copy resulted file to docker container

mvn clean package

docker exec sonarqube-8.9.3-community rm /opt/sonarqube/extensions/plugins/$(docker exec sonarqube-8.9.3-community ls /opt/sonarqube/extensions/plugins/ | grep checkstyle)

docker cp $(find . -name checkstyle-sonar-plugin-*-SNAPSHOT.jar) sonarqube-8.9.3-community:/opt/sonarqube/extensions/plugins

  1. restart docker
docker stop sonarqube-8.9.3-community && sleep 5 && docker start sonarqube-8.9.3-community
  1. recheck New Rules at http://localhost:9000/coding_rules#languages=java|repositories=checkstyle , activate Rules. sonar in docker Login: admin/admin

In case problems, login by ssh: docker exec -i -t sonarqube-8.9.3-community /bin/bash

4.1) Activate some Checkstyle rules (all of them are not active by default)

  1. try to run on some sources

mvn sonar:sonar

  1. Recheck results at http://localhost:9000/dashboard/index/1

useful command for repetitive executions: mvn clean package && docker cp $(find . -name *SNAPSHOT.jar) sonarqube-8.9.3-community:/opt/sonarqube/extensions/plugins && docker stop sonarqube-8.9.3-community && sleep 5 && docker start sonarqube-8.9.3-community

get logs from not running contianer:

docker cp sonarqube-8.9.3-community:/opt/sonarqube/logs/sonar.log /tmp && less /tmp/sonar.log 
docker cp sonarqube-8.9.3-community:/opt/sonarqube/logs/web.log /tmp && less /tmp/web.log

view docker log:

journalctl -u docker.service