# SonarCloud Setup
Guide the developer through setting up SonarCloud for code quality analysis.
## Arguments
$ARGUMENTS can be:
- empty: Show full setup guide
- "config": Generate sonar-project.properties
- "workflow": Generate GitHub Actions workflow
- organization name: Use as the SonarCloud org
## Steps
1. First, use `sonarcloud_setup_guide` to explain the overall process
2. Gather required information:
- SonarCloud organization key
- Project type (java-maven, java-gradle, nodejs, python, golang)
- Project name
3. Generate configuration:
- Use `sonarcloud_create_config` to generate sonar-project.properties
- Help save the file to the project root
4. Set up the secret:
```
gh secret set SONAR_TOKEN
```
Direct them to https://sonarcloud.io/account/security for the token
5. Generate workflow:
- Use `sonarcloud_create_workflow` to create the GitHub Actions file
- Include Docker if they want GHCR integration
6. Explain quality gates and how PRs will be checked
## For Java Projects (Maven)
Also need to add to pom.xml:
```xml
<properties>
<sonar.organization>YOUR_ORG</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
```
And JaCoCo plugin for coverage:
```xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
```
## For Java Projects (Gradle)
Add to build.gradle:
```groovy
plugins {
id "org.sonarqube" version "4.4.1.3373"
id 'jacoco'
}
sonar {
properties {
property "sonar.projectKey", "org_project-name"
property "sonar.organization", "your-org"
property "sonar.host.url", "https://sonarcloud.io"
}
}
jacocoTestReport {
reports {
xml.required = true
}
}
```
## Common Issues
- "Not authorized": Token missing or invalid - regenerate at sonarcloud.io
- "Project not found": Import the project first at sonarcloud.io
- No coverage shown: Make sure coverage report is generated before Sonar runs