--- name: 112-java-maven-plugins-profile-sonar description: Sonar profile guidance for SonarQube and SonarCloud analysis. license: Apache-2.0 metadata: author: Juan Antonio BreƱa Moral version: 0.19.0 --- # Maven Plugins: pom.xml Configuration Best Practices ## Role You are a Senior software engineer with extensive experience in Java software development. ## Tone Treat the user as a knowledgeable partner. Preserve existing Maven configuration, explain trade-offs, and apply this reference only when the SKILL.md question flow selected this plugin or profile. ## Goal Configure Sonar profile only when selected by the user in `112-java-maven-plugins`. Read this reference after the SKILL.md orchestration has validated the Maven project, analyzed existing plugins/properties/profiles, and collected the user's plugin/profile selections. ## Constraints Apply only the selected Sonar profile configuration and preserve existing project configuration. - Read this reference only when the user selected the corresponding Maven plugin or profile in the centralized question flow. - Before adding configuration, check whether the plugin, property, reporting entry, support file, or profile already exists. - Never remove or replace existing Maven configuration without explicit user confirmation. - Add only the Maven properties, plugin configuration, profile configuration, and support files required by this reference. ## Steps ### Step 1: Add selected Maven properties Add only the properties needed for this selected plugin/profile. If a property already exists, preserve the current value unless the user explicitly confirms a change. ```xml UTF-8 UTF-8 3.9.10 [USER_SELECTED_JAVA_VERSION] 4.0.0.4121 ``` ### Step 2: SonarQube/SonarCloud Profile Configuration **Purpose**: Configure SonarQube/SonarCloud profile for comprehensive code quality analysis integration. **Dependencies**: Only execute if user selected "Sonar" in the SKILL.md question flow and provided Sonar configuration. Requires completion of the SKILL.md orchestration steps and selected property handling. **CRITICAL PRESERVATION RULE**: Only ADD this profile if it doesn't already exist. Never REPLACE or REMOVE existing profiles. ## Pre-Implementation Check **BEFORE adding Sonar profile, check if it already exists in the pom.xml:** If `` section with `sonar` profile already exists: Ask user "Sonar profile already exists. Do you want to enhance the existing configuration? (y/n)" If user says "n": Skip this step entirely. If user says "y": Proceed with adding missing configuration elements only. **CONDITIONAL EXECUTION**: Only execute this step if user selected "Sonar" in the SKILL.md question flow and provided Sonar configuration. ## Sonar Profile Configuration **ADD this profile to the `` section in pom.xml ONLY if it doesn't already exist:** ```xml sonar false REPLACE_WITH_SONAR_HOST_URL REPLACE_WITH_SONAR_ORGANIZATION REPLACE_WITH_SONAR_PROJECT_KEY REPLACE_WITH_SONAR_PROJECT_NAME ${project.version} src/main/java src/test/java target/classes target/test-classes target/jacoco.exec target/surefire-reports **/*Test.java,**/*IT.java ${java.version} org.sonarsource.scanner.maven sonar-maven-plugin ${maven-plugin-sonar.version} ``` ## Implementation Guidelines 1. **Replace Sonar placeholders** with actual values from the SKILL.md question flow: - `REPLACE_WITH_SONAR_HOST_URL` - `REPLACE_WITH_SONAR_ORGANIZATION` - `REPLACE_WITH_SONAR_PROJECT_KEY` - `REPLACE_WITH_SONAR_PROJECT_NAME` ## Usage Examples ```bash # Run Sonar analysis (requires token) ./mvnw clean verify sonar:sonar -Psonar -Dsonar.login=YOUR_TOKEN # For SonarCloud with GitHub Actions ./mvnw clean verify sonar:sonar -Psonar -Dsonar.login=$SONAR_TOKEN # Combined with JaCoCo ./mvnw clean verify sonar:sonar -Pjacoco,sonar -Dsonar.login=$SONAR_TOKEN ``` ## Validation After adding this profile, verify the configuration: ```bash # Validate Sonar profile (requires token) ./mvnw clean verify sonar:sonar -Psonar -Dsonar.login=YOUR_TOKEN ``` #### Step Constraints - **MUST** only add Sonar profile if Sonar integration was selected in the SKILL.md question flow - **MUST** check if profile already exists before adding - **MUST** ask user permission before modifying existing profile configuration - **MUST** configure Sonar properties with actual values from the SKILL.md question flow - **MUST** use selected version properties for plugin versions - **MUST** skip this step entirely if Sonar was not selected