Automatic creation of sonar projects fails

Hi There,

So we’ve started aligning with the new GitHub defaults of the main branch being main instead of master. However, when trying to run the sonarscanner on the projects, they’re failing with Could not find a default branch to fall back on.. (These are new projects it hasn’t seen before so we can’t modify configuration)

I’m assuming this is related to the defaults of the target branch being master. However, weird enough when I tried switching things back to master it still wouldn’t automatically create project.

We have a workaround, which is just to run the scanner locally since sonarqube is forcing the branch name in our pipeline, however, this shouldn’t be the way forward for us.

Is there anything we’re able to do about this?

Specifics

Runner

Jenkins CI SonarQube plugin

Languages

Typescript

Error Trace

Expand
11:58:29.210 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:51)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
	at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:121)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
	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(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	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)
Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:51)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:49)
	... 34 more
Caused by: Could not find a default branch to fall back on.

Current Workaround

Creating the project manually and changing branch master to main

Hi @Lavoaster!

Did you onboarded the projects using the SonarCloud UI before doing the scan?

At GitHub, did you configured the main branch to be the default, instead of master? Did you keep the master branch or deleted it?

Is your project public, so we can have a look into it (URL)?

Thanks.

Hey @Alexandre_Holzhey!

Nope. AFAIK We’ve never had to manually create a project on Sonarcloud.

Kind of, it was main by default, due to the changes github pushed out on 1st October, and this repo was created after that.

Unfortunately not.

I’ve seen a number of people with the same kind of issue when using Azure DevOps, and although we use the Jenkins SonarQube plugin, I think they operate in the same way in terms of forcing -Dsonar.branch.name=<branch> to be set. One of my workaround above was to literally run the scanner locally without the branch name set, and that worked.

Hi @Lavoaster! Thanks for the information.

For GitHub projects, you should use the UI on boarding feature, otherwise you gonna miss PR decorations, for example, plus also have this current error.

I was able to reproduce it locally, using the scanner like you. If i create a new project at GitHub (with the brand new main branch) and start a local scanner like Jenkins CI does (using the sonar.branch.name parameter), it fails with the same error. Since the project was not on boarded, SonarCloud tries to find the default branch but we guess that it is called master (still widely used), since we can’t guess the correct one. If you do the on boarding procedure, the main branch will be set as the default one at SonarCloud and everything should be fine.

If you remove the branch parameter, the scan will succeed but in the end you will have a master branch at SonarCloud, not the expected main one (because master is still the best guessing we can do). Also, no PR decoration will happen.

The auto provisioning feature from SonarCloud creates all projects transparently, without requiring to use the UI on boarding. This feature will be dropped in the near future, just because it leads to problems like this.

1 Like

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