Skip to content

Commit c3b5ac7

Browse files
chore: upgrade sonarqube version to latest (#112)
* chore: upgrade sonarqube version to latest * docs: add build & deploy guide, update docker-compose for SonarQube compatibility - Add BUILD_AND_DEPLOY.md with full local dev workflow - Update docker-compose image to sonarqube:26.1.0.102418-community (compatible with plugin API 13.6) - Remove obsolete 'version: 3.3' from docker-compose --------- Co-authored-by: Johanna DUIGOU <jduigou.dev@gmail.com>
1 parent 127cbbb commit c3b5ac7

5 files changed

Lines changed: 172 additions & 6 deletions

File tree

BUILD_AND_DEPLOY.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Build & Deploy the Plugin to SonarQube (Local Docker)
2+
3+
Complete guide to build the creedengo-android project and deploy the plugin to a local SonarQube instance via Docker.
4+
5+
## Prerequisites
6+
7+
- **Java 11** (JDK) — required by the project
8+
- **Maven 3.8+**
9+
- **Gradle 6.9.2** — needed to build CodeNarc
10+
- **Docker** and **Docker Compose**
11+
12+
Verify installations:
13+
14+
```sh
15+
java -version # should display 11.x
16+
mvn -version
17+
gradle -version # 6.9.2
18+
docker --version
19+
docker compose version
20+
```
21+
22+
## Step 1: Prepare CodeNarc
23+
24+
The Android plugin uses [CodeNarc](https://codenarc.org/) to analyze Gradle files. It must be built separately and installed in the local Maven repository.
25+
26+
```sh
27+
# From the project root
28+
./tool_prepare-codenarc.sh
29+
```
30+
31+
This script does two things:
32+
1. Builds CodeNarc (in `codenarc-converter/CodeNarc/`) via Gradle
33+
2. Installs the resulting JAR into the local Maven repository (`~/.m2/repository`)
34+
35+
> **Common issue**: if Gradle uses the wrong Java version, force it with `export JAVA_HOME=$(/usr/libexec/java_home -v 11)` before running the script. Ideally, use [sdkman](https://sdkman.io/) to manage Java versions.
36+
37+
## Step 2: Build the Plugin
38+
39+
```sh
40+
# From the project root
41+
./tool_build.sh
42+
```
43+
44+
Or manually:
45+
46+
```sh
47+
mvn clean package -DskipTests
48+
```
49+
50+
The plugin JAR is generated at:
51+
```
52+
android-plugin/target/creedengo-android-2.0.0-SNAPSHOT.jar
53+
```
54+
55+
It is also automatically copied to `./lib/` by the Maven build.
56+
57+
### Run tests (optional)
58+
59+
```sh
60+
mvn clean verify
61+
```
62+
63+
## Step 3: Start SonarQube with Docker Compose
64+
65+
The `android-plugin/docker-compose.yml` file is preconfigured to mount the plugin JAR directly into SonarQube.
66+
67+
> **Important**: The Docker image version must be compatible with the `sonarqube.version` declared in the root `pom.xml`. If SonarQube rejects the plugin at startup, check the logs (`docker compose logs sonar`) for an API version mismatch.
68+
69+
```sh
70+
cd android-plugin
71+
docker compose up -d
72+
```
73+
74+
This starts:
75+
- **SonarQube Community Edition** on port `9000`
76+
- **PostgreSQL 12** as the database
77+
78+
The plugin is mounted via a bind mount:
79+
```
80+
./target/creedengo-android-2.0.0-SNAPSHOT.jar → /opt/sonarqube/extensions/plugins/
81+
```
82+
83+
### Check startup
84+
85+
```sh
86+
docker compose logs -f sonar
87+
```
88+
89+
Wait for the `SonarQube is operational` message (may take 1-2 minutes).
90+
91+
## Step 4: Access SonarQube
92+
93+
1. Open http://localhost:9000
94+
2. Log in with default credentials: **admin / admin**
95+
3. SonarQube will ask to change the password on first login
96+
97+
### Verify the plugin is installed
98+
99+
Go to **Administration → Marketplace → Installed** (or **Administration → Plugins**).
100+
101+
The "Creedengo Android Java plugin" should appear in the list.
102+
103+
You can also check available rules:
104+
- **Rules → Repository**: search for "creedengo" to see the plugin's rules
105+
106+
## Step 5: Analyze an Android Project
107+
108+
To run an analysis on a local Android project:
109+
110+
```sh
111+
cd /path/to/your/android-project
112+
113+
mvn sonar:sonar \
114+
-Dsonar.host.url=http://localhost:9000 \
115+
-Dsonar.login=admin \
116+
-Dsonar.password=your_new_password
117+
```
118+
119+
Or with a token (recommended):
120+
121+
```sh
122+
# Generate a token in SonarQube: My Account → Security → Generate Tokens
123+
124+
mvn sonar:sonar \
125+
-Dsonar.host.url=http://localhost:9000 \
126+
-Dsonar.token=squ_xxxxxxxxxxxxx
127+
```
128+
129+
## Development Cycle
130+
131+
When you modify the plugin and want to test changes:
132+
133+
```sh
134+
# 1. Rebuild the plugin
135+
cd /path/to/creedengo-android
136+
mvn clean package -DskipTests
137+
138+
# 2. Restart SonarQube to load the new JAR
139+
cd android-plugin
140+
docker compose restart sonar
141+
142+
# 3. Wait for SonarQube to be operational, then re-run the analysis
143+
```
144+
145+
## Stop / Clean Up
146+
147+
```sh
148+
cd android-plugin
149+
150+
# Stop containers (data is preserved in volumes)
151+
docker compose down
152+
153+
# Stop AND remove volumes (full reset)
154+
docker compose down -v
155+
```
156+
157+
## Troubleshooting
158+
159+
| Problem | Solution |
160+
|---------|----------|
161+
| `Permission denied` on .sh scripts | `chmod +x tool_*.sh` |
162+
| SonarQube won't start (Elasticsearch) | Increase `vm.max_map_count`: `sudo sysctl -w vm.max_map_count=262144` |
163+
| Plugin not visible after restart | Check that the JAR exists in `android-plugin/target/` and that the name matches the bind mount in `docker-compose.yml` |
164+
| Plugin rejected (API version mismatch) | Update the Docker image version to match `sonarqube.version` in `pom.xml` |
165+
| CodeNarc compilation error | Verify that `JAVA_HOME` points to Java 11 |
166+
| Port 9000 already in use | Find what's using it: `lsof -i :9000`, then either stop it or change the port in `docker-compose.yml` to e.g. `"9001:9000"` |
167+
| `OutOfMemoryError` during Maven build | `export MAVEN_OPTS="-Xmx1024m"` |

android-plugin/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
version: "3.3"
21
services:
32
sonar:
4-
image: sonarqube:9.9-community
3+
image: sonarqube:26.1.0.102418-community
54
container_name: sonar_creedengo_android
65
ports:
76
- "9000:9000"

android-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<dependencies>
2525
<dependency>
26-
<groupId>org.sonarsource.sonarqube</groupId>
26+
<groupId>org.sonarsource.api.plugin</groupId>
2727
<artifactId>sonar-plugin-api</artifactId>
2828
</dependency>
2929

codenarc-converter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependencies>
2525

2626
<dependency>
27-
<groupId>org.sonarsource.sonarqube</groupId>
27+
<groupId>org.sonarsource.api.plugin</groupId>
2828
<artifactId>sonar-plugin-api</artifactId>
2929
</dependency>
3030

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
4242
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
4343

44-
<sonarqube.version>9.4.0.54424</sonarqube.version>
44+
<sonarqube.version>13.6.0.4371</sonarqube.version>
4545
<sonarjava.version>7.15.0.30507</sonarjava.version>
4646

4747
<sonar.organization>green-code-initiative</sonar.organization>
@@ -69,7 +69,7 @@
6969
<dependencies>
7070
<!-- MAIN sources dependencies -->
7171
<dependency>
72-
<groupId>org.sonarsource.sonarqube</groupId>
72+
<groupId>org.sonarsource.api.plugin</groupId>
7373
<artifactId>sonar-plugin-api</artifactId>
7474
<version>${sonarqube.version}</version>
7575
<scope>provided</scope>

0 commit comments

Comments
 (0)