Reputation:
I'm performing an analysis with Sonar but I get the following error:
Error during SonarQube Scanner execution
java.lang.IllegalStateException: No files nor directories matching 'target/classes'
In my project I've the target directory but no classes directory or files, what should be in there for the analysis to work?
Upvotes: 12
Views: 27204
Reputation: 1
For me , it was giving this error because I forgot to do maven clean install after I cloned the project from github . So you should also try to do "maven clean install" before running the sonar command ! To do "maven clean install" you can go the terminal and write "maven clean install"
Upvotes: 0
Reputation: 434
The Answer from @bsaunter works. I have to add that you may encounter this error also when migrating from gradle 5.x to 6.x, got to your build/intermediate/javac/debug folder and look what is generating sonarqube, the name of the folder could be "classes"
Look for this property "sonar.java.binaries" on wherever file in your project folder and replace the value for the correct generated folder by sonarqube.
Upvotes: 1
Reputation: 1616
One of the reasons might be that Sonar cannot find that directory if you do analysis before building your project.
The target/classes
directory does not exist before you started building the project using maven.
Try this value to workaround:
sonar.java.binaries=target
or
sonar.java.binaries=.
Upvotes: 19
Reputation: 4131
Sometimes some modules could not generate sources, for example, working with Maven, those modules packaging as 'pom'.
To avoid sonar analysing them, specify in your sonar.properties the property sonar.modules with the ones are generating sources.
Upvotes: 2
Reputation: 4822
for the poor lost soul who finds themselves on this thread, you may encounter this error when migrating from gradle 4.x to 5.x as the classes folder is renamed from classes
to app_classes
and it's no longer variant/flavor
it's variantFlavor
- you can verify by building your app and looking in the build folder
I had to change this sonarqube property in my build.gradle
property "sonar.java.binaries", "build/intermediates/app_classes/betaDebug,build/tmp/kotlin-classes/betaDebug"
Upvotes: 1
Reputation: 11
I'm sure that you figured this out already. However, here's what you need to do for Java projects built using Maven.
If you're using the path "**/target/classes" then let's assume that you're using Maven for your builds. You would perform a "mvn clean package" for your Sonarqube Scanner to work.
Once you have used maven to compile and package into the standard directory ("./target/classes") then just pass the appropriate setting to the scanner (either through a configuration file or the command line). An example of passing through the command line is below.
${scanner_home}/bin/sonar-scanner
-Dsonar.login=<SONAR KEY>
-Dsonar.projectKey=<PROJECT KEY>
-Dsonar.branch.name=<BRANCH_NAME>
-Dsonar.branch.target=<RELEASABLE BRANCH>
-Dsonar.sources=./src
-Dsonar.java.binaries=./target/classes
Notice that I'm using a relative path for the sonar.sources and sonar.java.binaries settings. I do this in a Jenkins build pipeline and made this configurable since I also build PHP and use Composer, Gulp, npm, and other tool in my build process. (If you're using the SonarQube Scanner for Maven, then you would put this into a property file.)
Upvotes: 1