sonar.projectKey unknown

I have many project files in my project folder. I want to run only one project from that folder. I have added a sonar-scanner-properties in project folder. I specified sonar.projectKey with desired project file name, but still getting same error : “You must define the following mandatory properties for ‘Unknown’: sonar.projectKey”

Hi,

Welcome to the community!

Your problem isn’t clear to me from your post. Are you running analysis from the project folder? Is your properties file in the directory you’re running analysis from? And did you really name it sonar-scanner-properties? The file name that’s recognized by default is sonar-project.properties.

 
HTH,
Ann

Hello campbell,
I want to analyse my c++ project using MSBuild scanner on my private company server https://sonarqube.####.com, I go through the MSBuild sonar-scanner documentation. I am getting an error.

I am using this steps: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/

SonarScanner.MSBuild.exe begin /k:"project-key"
MSBuild.exe <path to solution.sln> /t:Rebuild
SonarScanner.MSBuild.exe end

I am also adding Build wrapper using this steps :https://sonarqube.factset.com/documentation/analysis/languages/cfamily/

Error is :

INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 24.514s
ERROR: Error during SonarQube Scanner execution
java.nio.file.InvalidPathException: Illegal char <
> at index 7: C:Users
sharma07DesktopSonarQubebuild-wrapper-win-x86build-wrapper-win-x86build_wrapper_output_directory/build-wrapper-dump.json
        at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
INFO: Final Memory: 33M/117M
        at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
        at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
        at java.base/java.nio.file.Path.of(Path.java:147)
        at java.base/java.nio.file.Paths.get(Paths.java:69)
        at com.sonar.cpp.plugin.CFamilySensor.lambda$execute$0(CFamilySensor.java:123)
        at java.base/java.util.Optional.map(Optional.java:258)
        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:123)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
        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(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        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:185)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
        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:
INFO: ------------------------------------------------------------------------
The SonarQube Scanner did not complete successfully
12:51:06.844  Post-processing failed. Exit code: 1

May you help me to figure out from this error.

I will wait for your reply.

Thank you.

Hi,

The error is pretty clear. Somewhere in your analysis parameters is a bad path. You need to start by resolving that.

 
Ann

Thank you so much, I got, where did I make mistakes.

Be happy and safe from COVID-19.

I create the sonar property as per sonar documentation and also placed that property in the root of my project which I want to scan. But still the unknown sonar project key error is occurs.

D:\Proj_Sonarqube\MacawInsurance>sonar-scanner
INFO: Scanner configuration file: D:\Proj_Sonarqube\sonar-scanner-4.4.0.2170-windows\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.4.0.2170
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users\akash.chatterjee\.sonar\cache
INFO: Scanner configuration file: D:\Proj_Sonarqube\sonar-scanner-4.4.0.2170-windows\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.4.2
INFO: Default locale: "en_IN", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=55ms
INFO: Server id: BF41A1F2-AXTYGVmxvMLcO3vzTdtw
INFO: User cache: C:\Users\akash.chatterjee\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=39ms
INFO: Load/download plugins (done) | time=356ms
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2.075s
INFO: Final Memory: 5M/20M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Hi @Akash_Chatterjee,

Welcome to the community!

Your log includes this:

which indicates that your properties file wasn’t found/recognized.

Can you expand on this?

 
Ann

@ganncamp can you guide me on one thing ? Is that different sona property used in Java project and Javascript project ?

Hi,

Yes and no. The basics, such as sonar.projectKey are the same, but language-specific properties do vary. For instance, you won’t need to specify sonar.java.binaries for a JavaScript project.

 
Ann