How to exclude Java files

I am evaluating sonar cloud with msbuild project. However, there is an error related to Java files. The 3rdparty code includes Java files but it is not used in my project at all. I added exclusion options but the scanner fails. Here are my property file and log below.

sonar-project.properties

sonar.exclusions=*.java
sonar.coverage.exclusions=*.java

log

E:\Build\TSS>C:\Users\admin\.sonar\sonar-scanner-4.7.0.2747-windows\bin/sonar-scanner.bat -D"sonar.organization=tomocubemitkdev" -D"sonar.projectKey=tomocubemitkdev_tomocubesoftwarestation" -D"sonar.sources=." -D"sonar.cfamily.build-wrapper-output=bw-output" -D"sonar.host.url=https://sonarcloud.io"
INFO: Scanner configuration file: C:\Users\admin\.sonar\sonar-scanner-4.7.0.2747-windows\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: E:\Build\TSS\sonar-project.properties
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users\admin\.sonar\cache
INFO: Scanner configuration file: C:\Users\admin\.sonar\sonar-scanner-4.7.0.2747-windows\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: E:\Build\TSS\sonar-project.properties
INFO: Analyzing on SonarCloud
INFO: Default locale: "ko_KR", source code encoding: "x-windows-949" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=1502ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: C:\Users\admin\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=326ms
INFO: Load/download plugins (done) | time=628ms
INFO: Loaded core extensions: developer-scanner
INFO: Load project settings for component key: 'tomocubemitkdev_tomocubesoftwarestation'
INFO: Load project settings for component key: 'tomocubemitkdev_tomocubesoftwarestation' (done) | time=292ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: tomocubemitkdev_tomocubesoftwarestation
INFO: Base dir: E:\Build\TSS
INFO: Working dir: E:\Build\TSS\.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=298ms
INFO: Check ALM binding of project 'tomocubemitkdev_tomocubesoftwarestation'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'tomocubemitkdev_tomocubesoftwarestation' (done) | time=281ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=287ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=342ms
INFO: Load active rules
INFO: Load active rules (done) | time=10353ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Organization key: tomocubemitkdev
INFO: Load project repositories
INFO: Load project repositories (done) | time=289ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/build-wrapper-dump.json, *.java
INFO: 8526 files indexed...  (last one was Applications/TomoAnalysis/BusinessRule/BasicAnalysisTime/UseCase/BasicAnalysisTimeUseCase.dir/Debug/BasicAna.87387F59.tlog/link.read.1.tlog)
INFO: 18717 files indexed...  (last one was Components/TC.HW.DMDControl/utility/PACKAGE.vcxproj.filters)
INFO: 32260 files indexed...  (last one was Extern/CTK/src/CTK/Libs/Scripting/Python/Widgets/Plugins/CMakeLists.txt)
INFO: 43070 files indexed...  (last one was Extern/HDF5/src/HDF5-build/examples/h5_shared_mesg.dir/Debug/h5_shared_mesg.tlog/CL.command.1.tlog)
INFO: 53338 files indexed...  (last one was Extern/ITK/src/ITK/Modules/Filtering/ImageFeature/test/Baseline/SwirledUSM_Defaults.png.md5)
INFO: 62913 files indexed...  (last one was Extern/ITK/src/ITK/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dgges.c)
INFO: 72046 files indexed...  (last one was Extern/ITK/src/ITK-build/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMEXD.dir/Debug/gdcmMaximumLengthSub.obj)
INFO: 81358 files indexed...  (last one was Extern/OpenCV/src/OpenCV/samples/dnn/text_detection.cpp)
INFO: 92102 files indexed...  (last one was Extern/VTK/src/VTK/Filters/HyperTree/Testing/Python/TestHyperTreeGrid3DZReflection.py)
INFO: 103444 files indexed...  (last one was Extern/VTK/src/VTK/ThirdParty/pegtl/vtkpegtl/include/tao/pegtl/internal/list_must.hpp)
INFO: 113550 files indexed...  (last one was Extern/VTK/src/VTK-build/Rendering/OpenGL2/vtkTestOpenGLVersion.dir/Debug/vc142.pdb)
INFO: 122758 files indexed
INFO: 1 file ignored because of inclusion/exclusion patterns
INFO: Quality profile for c: Sonar way
INFO: Quality profile for cpp: Sonar way
INFO: Quality profile for cs: Sonar way
INFO: Quality profile for css: Sonar way
INFO: Quality profile for java: Sonar way
INFO: Quality profile for js: Sonar way
INFO: Quality profile for json: Sonar way
INFO: Quality profile for objc: Sonar way
INFO: Quality profile for php: Sonar way
INFO: Quality profile for plsql: Sonar way
INFO: Quality profile for py: Sonar way
INFO: Quality profile for ruby: Sonar way
INFO: Quality profile for scala: Sonar way
INFO: Quality profile for swift: Sonar way
INFO: Quality profile for ts: Sonar way
INFO: Quality profile for web: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: Quality profile for yaml: Sonar way
INFO: ------------- Run sensors on module tomocubemitkdev_tomocubesoftwarestation
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=298ms
INFO: Sensor JavaSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2:23.017s
INFO: Final Memory: 30M/148M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.
        at org.sonar.java.classpath.ClasspathForMain.init(ClasspathForMain.java:75)
        at org.sonar.java.classpath.AbstractClasspath.getElements(AbstractClasspath.java:319)
        at org.sonar.java.SonarComponents.getJavaClasspath(SonarComponents.java:203)
        at org.sonar.java.JavaFrontend.<init>(JavaFrontend.java:93)
        at org.sonar.plugins.java.JavaSensor.execute(JavaSensor.java:112)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:440)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:436)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:394)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Hi,

Welcome to the community!

The exclusion paths you’ve specified exclude .java files in project root. To exclude them recursively, use this pattern: **/*.java.

* is 0-n characters
** is 0-n directories

 
HTH,
Ann

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.