"Malformed key for Project" error in Sonar Gradle Bamboo task

I am using the Sonar Gradle task in Bamboo to run Sonar checks on our projects. This works fine for five out of six projects:

  • :heavy_check_mark: Alpha
  • :heavy_multiplication_x: Alpha Lib
  • :heavy_check_mark: Beta
  • :heavy_check_mark: Gamma
  • :heavy_check_mark: Gamma Lib
  • :heavy_check_mark: Delta

For the Alpha Lib, this task fails with the following error message:

* What went wrong:
Execution failed for task ':sonarqube'.
> Malformed key for Project: 'io.company.project:AlphaLib'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

The error itself is nice and descriptive, and I know what I should do in order to fix it, namely change the project key to alpha-lib, however…

I have no idea just how I am supposed to do it. I can’t find a setting for this anywhere in Bamboo, and for some strange reason, this error does not occur for the Gamma Lib, wven though it should have the same problem. I have also compared the build.gradle files for the Alpha Lib and Gamma Lib, but I can’t see anything in the build.gradle of the Gamma Lib that would magically change the project key from Gamma Lib to gamma-lib, which is what I can see somehow arrives at SonarQube.

For reference, this is what the build.gradle of the Alpha Lib looks like:

buildscript {
	repositories {
		maven {
			url "https://plugins.gradle.org/m2/"
		}
	}
	dependencies {
		classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
	}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'jacoco'

def sonarqubePluginId = "org.sonarqube"
final hasPlugin = project.getPlugins().hasPlugin(sonarqubePluginId);
if (hasPlugin) {
	final Plugin plugin = project.getPlugins().getPlugin(sonarqubePluginId)
} else {
	apply plugin: "org.sonarqube"
}

group = 'io.company.project'
version = '0.0-SNAPSHOT'
description = 'alpha Lib'
idea {
    module {
        sourceDirs += file('src')
        testSourceDirs+=file('test')
        excludeDirs += file('lib')

    }
}

jacocoTestReport {
	reports {
		xml.enabled true
	}
}

plugins.withType(JacocoPlugin) {
	tasks["test"].finalizedBy 'jacocoTestReport'
}

And for contrast, here is the build.gradle for the Gamma Lib, which as mentioned before works just fine:

buildscript {
	repositories {
		maven {
			url "https://plugins.gradle.org/m2/"
		}
	}
	dependencies {
		classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
	}
}

plugins {
    id 'java'
    id 'java-library'
    id 'maven-publish'
	id "jacoco"
}

def sonarqubePluginId = "org.sonarqube"
final hasPlugin = project.getPlugins().hasPlugin(sonarqubePluginId);
if (hasPlugin) {
	final Plugin plugin = project.getPlugins().getPlugin(sonarqubePluginId)
} else {
	apply plugin: "org.sonarqube"
}

compileJava {
    sourceCompatibility = "11"
    targetCompatibility = JavaVersion.VERSION_11
}
configurations {
    compile.exclude module: 'spring-boot-starter-logging'
}

repositories {
    mavenLocal()
    maven {
        url = 'https://repo.maven.apache.org/maven2'
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'log4j:log4j:1.2.17'
    compile 'org.slf4j:slf4j-log4j12:1.7.25'
    compile 'commons-logging:commons-logging:1.2'
    compile group: 'org.msgpack', name: 'msgpack-core', version: '0.8.16'
    compile 'com.google.guava:guava:25.1-jre'
    compile 'commons-io:commons-io:2.6'
    compile 'io.socket:socket.io-client:1.0.0'
    compile 'org.xerial:sqlite-jdbc:3.25.2'
    compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.61'
	
    testCompile('org.junit.jupiter:junit-jupiter-api:5.5.2')
    testCompile('org.junit.jupiter:junit-jupiter-engine:5.5.2')
    testCompile('org.junit.vintage:junit-vintage-engine:5.5.2')
    testCompile 'com.tngtech.jgiven:jgiven-junit5:1.0.0-RC4'
    testCompile('org.mockito:mockito-junit-jupiter:2.28.2')
    testCompile('org.mockito:mockito-core:2.28.2')}

test {
    useJUnitPlatform()
}

group = 'io.company.project'
version = '0.0-SNAPSHOT'
description = 'Gamma Lib'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

jacocoTestReport {
	reports {
		xml.enabled true
	}
}

plugins.withType(JacocoPlugin) {
	tasks["test"].finalizedBy 'jacocoTestReport'
}

(In case you’re wondering about the conditional import, this is because the Lib projects need to be built both dependently and independently, and thus have trouble importing the sonarqube plugin in a more simple way).

Summing it up, the question would be how to get rid of the error message, e.g. by setting the project key somewhere.

Thanks ins advance,
Kira

I now managed to figure this one out.

The project key it complained about was located in the settings.gradle. Once I changed it from “Alpha Lib” to “alpha-lib” in there, everything worked fine.