Search code examples
javamavenintellij-ideasonarqube

SonarQube doesn't analyze the main java code with IntelliJ and Maven


I'm using IntelliJ with Maven for my project and i have to analyze it with SonarQube, but when I scan my project with the command provided by the webApp it only analyzes the pom.xml file ignoring the rest of the project.

Analysis results

clean install sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login="the corresponding key here"

My pom.xml (what is inside the project tag):

<groupId>cl.itau.simulacionCredito</groupId>
<artifactId>SimulacionCreditoIntelliJ</artifactId>
<version>1.0</version>
<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>RELEASE</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.beust/jcommander -->
    <dependency>
        <groupId>com.beust</groupId>
        <artifactId>jcommander</artifactId>
        <version>1.72</version>
    </dependency>
</dependencies>
<properties>
    <maven.compiler.source>6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <excludes>
                    <exclude>**/HomeTest.java</exclude>
                    <exclude>**/PropuestaTest.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>3.0.0-M1</version>
        </plugin>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.5.0.1254</version>
        </plugin>
    </plugins>
</build>

<distributionManagement>
    <repository>
        <id>SimulacionCredito</id>
        <name>SimulacionCredito</name>
        <url>file:C:\Users\Pc\IdeaProjects</url>
    </repository>
</distributionManagement>

I also tried to use this inside the configuration tag:

<sonar.sources>src/main/java</sonar.sources> 

And this happened:

Second analysis

My settings.xml in Maven's conf:

<pluginGroups>
    <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
  </servers>

  <mirrors>
  </mirrors>

  <profiles>
    <profile>
       <id>sonar</id>
       <activation>
           <activeByDefault>true</activeByDefault>
       </activation>
       <properties>
           <sonar.host.url>
             http://localhost:9000
           </sonar.host.url>
        </properties>
     </profile>
  </profiles>

I've been adding things to the POM because of different errors while trying to fix this.

I have the latest version of SonarQube installed.


Solution

  • So, the problem was that IntelliJ was configured with Java SE Development Kit 11, I downgraded to Java SE Development Kit 8u181 and configured the POM so Maven works with that change, I executed the scanner again and it worked.

    Changes to pom.xml:

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    
        <sonar.sources>src/main/java</sonar.sources>
    </properties>
    

    added:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
             <version>3.8.0</version>
             <configuration>
                <source>8</source>
                <target>8</target>
             </configuration>
    </plugin>
    

    New analysis results