Issue when scanning import statements


Sonarqube v7.7

I am trying to scan import statements to identify the usage of some specific libraries with the help of javafilescanner and public void scanFile method. It is working in local but when i deployed it into sonarqube server and run the scanner, I am getting following error.

Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin: failed: A required class was missing while executing org.sonarsource.scanner.maven:sonar-maven-plugin: org/sonar/java/checks/helpers/ExpressionsHelper
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/****/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/
[ERROR] urls[1] = file:/C:/Users/****/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/C:/Users/****/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/C:/Users/****/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[4] = file:/C:/Users/****/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/
[ERROR] urls[5] = file:/C:/Users/****/.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]]

I have deleted .m2 folder and tried running, but getting same error. Can you please help me in resolving the issue.

The ExpressionHelper class is not part of the api package and it is thus not available at runtime.
You would have to avoid using classes outside of the api package when writing your rule, that will work in unit tests but the class is not shared at runtime in classloader. To make this work you can copy the method in expressionhelper.

1 Like

Thanks Nicolas… I will work on that.

Thank you very much Nicolas, It’s true I had problems with ExpressionHelper utilized in my Custom Rules for SonarQube: when I put my jar plugin of rules in sonarqube, my rules were recognized but when I built my basicproject (with a bug to check my customrules) It went always in error, so I copied and pasted some packages from another project (sonar-java-master - frontend) and I used the classes in my packages and no more in other downloaded. My" mvn clean verify sonar:sonar" finally it worked.