Unauthorized Exception on first SonarQube analysis

Hello there,

I’m having issues with Sonarcloud, where following the “3 easy steps.” for a first Java Gradle Project analysis ends up with

“You’re not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.”.

I’ve just created an account (from Github), which is Administrator of its own Organization (& sole member) and used the “Analyze new project” button on the homepage .

I tried both the default existing organization and creating a new one, generated a token, and ran the provided command after adding org.sonarqube to my Gradle plugins
./gradlew sonarqube

I don’t get what I should do about this issue, as checking my permissions confirmed everything is correctly ticked.

Am I missing something here ?

Chances are that the SonarCloud project key inferred from your Gradle configuration is already used by someone else (currently, project keys are uniq across organizations). And the tutorial does not take into account this case.

To fix the problem, you need to specify your own project key:

  • Either on the command line. You simply need to add:
  • Or inside your build.gradle file:
sonarqube {
    properties {
        property 'sonar.projectKey', 'my_own_project_key'

Sorry for the late reply, it seems to be working fine now, but I’ll keep your suggestion around in case I reproduce this issue again.

I’m surprised it’d be a key collision as I tried with multiple keys, but might have been some bad luck :thinking:

Thanks, this worked like a charm.

Can we update the documentation so that it will help others not to spend issue on this.

I have exactly the same problem, but adding a projectKey also did not help.

./gradlew sonarqube \
 -Dsonar.organization=rexch \
 -Dsonar.host.url=https://sonarcloud.io \
 -Dsonar.login=<snip> -D sonar.projectKey=blah
* What went wrong:

Execution failed for task ':sonarqube'.

&gt; You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the     SonarQube server. Please contact your SonarQube administrator.

It’s not the exactly the same problem.
The error message is related to the right associated to your token.
Check that the user have the “Execute Analysis” right and if you don’t provision the project on SonarCloud, he should also have the “Create Projects” right.