SonarQube扫描Maven项目时出现StringUtils类缺失错误
Hey there, I’ve dealt with this exact error before when running SonarQube scans on Maven projects—frustrating, especially when the project itself runs fine! Let’s walk through the most likely fixes to get your scan working:
1. Update the SonarQube Maven Plugin Version
Older versions of the sonar-maven-plugin can have classpath conflicts or missing dependencies that trigger this issue. Try explicitly setting the latest stable version in your pom.xml:
<build> <plugins> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.10.0.2594</version> <!-- Grab the latest version from Maven Central if needed --> </plugin> </plugins> </build>
2. Verify Your Commons-Lang Dependency Scope
Since your project runs normally, the dependency is present—but Sonar’s scan might not pick it up if the scope is set to runtime or provided. Update the dependency to use compile scope (or add it if it’s missing entirely):
<dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> <!-- Match the actual version used in your project --> <scope>compile</scope> </dependency>
3. Explicitly Add Commons-Lang to the Sonar Plugin’s Classpath
If the above doesn’t work, force the Sonar plugin to include the commons-lang dependency directly by adding it to the plugin’s dependency block:
<build> <plugins> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.10.0.2594</version> <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> </dependencies> </plugin> </plugins> </build>
4. Clean Your Maven Cache and Rebuild
Sometimes corrupted Maven cache files cause dependency resolution issues during scans. Run these commands to reset and retry:
mvn clean install -U mvn sonar:sonar -Dsonar.host.url=http://localhost:32768 -Dsonar.login=27948f763e39322e99a8508c38a28385c22b57f8 -e
5. Check SonarQube Server Plugins
Make sure your SonarQube instance has the latest version of the SonarJava plugin installed. Outdated Java plugins often have compatibility issues with newer project dependencies. You can check and update this in your SonarQube admin panel under Marketplace.
Start with steps 3 and 4 first—those usually resolve this specific class-missing error for me. Let me know if any of these work for you!
内容的提问来源于stack exchange,提问作者johann

