microsoft / azuredevopslabs

Learn how you can plan smartly, collaborate better, and ship faster with a set of modern development services with Azure DevOps.
https://www.azuredevopslabs.com
MIT License
819 stars 914 forks source link

Managing technical debt with SonarQube and Azure DevOps - Maven Build failed #598

Open HMLTC opened 2 years ago

HMLTC commented 2 years ago

Please help. The Maven build step fails for both the YAML/non-YAML pipeline.

[INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 15.836 s [INFO] Finished at: 2021-12-27T00:19:27Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project myshuttle: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 [ERROR] ----------------------------------------------------- [ERROR] realm = plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy [ERROR] urls[0] = file:/home/vsts/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.1.2184/sonar-maven-plugin-3.9.1.2184.jar [ERROR] urls[1] = file:/home/vsts/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar [ERROR] urls[2] = file:/home/vsts/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar [ERROR] urls[3] = file:/home/vsts/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar [ERROR] urls[4] = file:/home/vsts/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.2.588/sonar-scanner-api-2.16.2.588.jar [ERROR] urls[5] = file:/home/vsts/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar [ERROR] Number of foreign imports: 1 [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]] [ERROR] [ERROR] ----------------------------------------------------- [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException The process '/usr/bin/mvn' failed with exit code 1 Could not retrieve code analysis results - Maven run failed.

juanandmsft commented 2 years ago

Same error here.

[INFO] SonarQube version: 9.2.4 [INFO] Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.680 s [INFO] Finished at: 2021-12-29T12:25:47Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project myshuttle: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 [ERROR] ----------------------------------------------------- [ERROR] realm = plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy [ERROR] urls[0] = file:/home/vsts/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.1.2184/sonar-maven-plugin-3.9.1.2184.jar [ERROR] urls[1] = file:/home/vsts/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar [ERROR] urls[2] = file:/home/vsts/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar [ERROR] urls[3] = file:/home/vsts/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar [ERROR] urls[4] = file:/home/vsts/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.2.588/sonar-scanner-api-2.16.2.588.jar [ERROR] urls[5] = file:/home/vsts/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar [ERROR] Number of foreign imports: 1 [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]] [ERROR] [ERROR] ----------------------------------------------------- [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

After some research, I was able to solve the UnsupportedClassVersionError error by adding a Java Tool Installer task before Maven task, as detailed in http://..azurecontainer.io:9000/dashboard?id=MyShuttle&selectedTutorial=azure-pipelines image

Then it fails parsing dates in setupStartEndTimes() and employeeTotalFees() :

employeeTotalFees(com.microsoft.example.FaresTest) Time elapsed: 0.001 sec <<< ERROR! java.text.ParseException: Unparseable date: "Jun 3, 2009 7:03:47 AM" at java.base/java.text.DateFormat.parse(DateFormat.java:395)

After trying out some date formats without success, I was able to complete the lab by commenting out exception handling code in FaresTest.java file, so code compiles successfully and it is sent to SonarQube for analysis, and finally pipeline shows SonarQube report.