|
| 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"` | |
0 commit comments