Behaviour of sonar-maven-plugin varies when maven-compiler-plugin
is/isn't defined. I spent some time to find out the proper setting.
Create a simple Java maven project and keep the pom.xml
simple.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>testing</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Execution
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:<version>:sonar -Dsonar.login=<token>
Case 1:
sonarqube-maven-plugin
version:3.7.0.1746
pom.xml
withmaven.compiler.release
defined.maven-compiler-plugin
is NOT defined inpom.xml
Result:
Configured Java source version (sonar.java.source): 5
Case 2:
sonarqube-maven-plugin
version:3.7.0.1746
pom.xml
withmaven.compiler.release
definedpom.xml
withmaven.compiler.source
definedmaven-compiler-plugin
is NOT defined inpom.xml
Result:
(It means the plugin can only get the version from source
instead of release
)
Configured Java source version (sonar.java.source): 17
Case 3:
sonarqube-maven-plugin
version:3.7.0.1746
pom.xml
withmaven.compiler.release
definedmaven-compiler-plugin
(3.8.1) is defined
Result:
(No idea why the version changes when maven compiler plugin is defined.)
Configured Java source version (sonar.java.source): 6
Case 4:
sonarqube-maven-plugin
version:3.7.0.1746
pom.xml
withmaven.compiler.release
definedmaven-compiler-plugin
(3.10.1) is defined
Result:
(No idea why the version changes when different version of maven compiler plugin is defined.)
Configured Java source version (sonar.java.source): 7
Case 5:
sonarqube-maven-plugin
version:3.9.1.2184
pom.xml
withmaven.compiler.release
definedmaven-compiler-plugin
is NOT defined inpom.xml
Result:
(Upgrading sonar maven plugin doesn't help.)
Configured Java source version (sonar.java.source): 5
Proper setting
sonarqube-maven-plugin
with version3.8.0
or above.Define
maven-compiler-plugin
inpom.xml
with version3.6.0
or above.Execution:
pom.xml