Hi there,
Is there a guide to getting sonar to work from init.gradle as opposed to using build.gradle? We are trying to get this to work and hitting an issue where it appears the analysis is done, we see in the logs that number of files has been analysed and that the upload has succeeded but we also don’t see any files or issues in SonarCloud.
The intent behind doing it this way is that we need to analyse lots of projects and I do not want to modify their build files and processes - we simply want to have sonar be an ‘add-on’ to the process’ for now.
What we done is as follows:
- put the following into init.gradle
allprojects {
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:4.2.1.3168"
}
}
apply plugin: 'java'
apply plugin: 'jacoco'
afterEvaluate { project ->
project.apply plugin: 'org.sonarqube'
}
}
- put into gradle.properties the following:
systemProp.sonar.host.url=https://sonarcloud.io
systemProp.sonar.projectKey=REDACTED-ON-PURPOSE-SK
systemProp.sonar.projectName=REDACTED-ON-PURPOSE-PN
systemProp.sonar.organization=REDACTED-ON-PURPOSE-ORg
systemProp.qualitygate.wait=true
- run gradle using:
gradle -Dsonar.token="REDACTED_TOKEN" -Dsonar.verbose=true -Dorg.gradle.daemon=false --init-script init.gradle --info --stacktrace properties sonar
Now, the thing is:
- we see that report is successfully uploaded
- we see that properties are set (which is consistent with successful update as, if this wasn’t correct, report could not be matched to correct organisation and project)
- we see in SonarCloud UI that the branch this is analysing is completed, and the timestamp when this was analysed is as expected and commit# matches and nicely links to Gitlab (which we use as CI)
- we did not analyse master branch yet (could this be cause of the problem?)
- but we see no issues and no code and no code coverage.
This looks like most likely culprit but I’m not sure what to do with this:
216 source files to be analyzed
[1066](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1066)> Task :sonar
[1067](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1067)Could not report issue with code highlighting, using plain text instead. Check whether the product is outdated.
[1068](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1068)java.lang.UnsupportedOperationException: null
[1069](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1069) at org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation.newMessageFormatting(DefaultIssueLocation.java:97)
[1070](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1070) at org.sonarsource.kotlin.plugin.InputFileContextImpl.message(InputFileContext.kt:94)
[1071](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1071) at org.sonarsource.kotlin.plugin.InputFileContextImpl.reportIssue(InputFileContext.kt:69)
[1072](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1072) at org.sonarsource.kotlin.api.AbstractCheck.reportIssue$sonar_kotlin_plugin(AbstractCheck.kt:66)
[1073](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1073) at org.sonarsource.kotlin.api.AbstractCheck.reportIssue$sonar_kotlin_plugin(AbstractCheck.kt:85)
[1074](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1074) at org.sonarsource.kotlin.api.AbstractCheck.reportIssue$sonar_kotlin_plugin$default(AbstractCheck.kt:80)
[1075](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1075) at org.sonarsource.kotlin.checks.SimplifiedPreconditionsCheck.visitFunctionCall(SimplifiedPreconditionsCheck.kt:79)
[1076](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1076) at org.sonarsource.kotlin.api.CallAbstractCheck.visitCallExpression(CallAbstractCheck.kt:42)
[1077](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1077) at org.sonarsource.kotlin.api.CallAbstractCheck.visitCallExpression(CallAbstractCheck.kt:27)
[1078](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1078) at org.jetbrains.kotlin.psi.KtCallExpression.accept(KtCallExpression.java:35)
[1079](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1079) at org.sonarsource.kotlin.visiting.KtChecksVisitor$visit$1$1$1.invoke(KtChecksVisitor.kt:39)
[1080](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1080) at org.sonarsource.kotlin.visiting.KtChecksVisitor$visit$1$1$1.invoke(KtChecksVisitor.kt:34)
[1081](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1081) at org.sonarsource.kotlin.plugin.MetricsUtilsKt.measureDuration(MetricsUtils.kt:26)
[1082](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1082) at org.sonarsource.kotlin.visiting.KtChecksVisitor.visit(KtChecksVisitor.kt:34)
[1083](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1083) at org.sonarsource.kotlin.visiting.KotlinFileVisitor.scan(KotlinFileVisitor.kt:28)
[1084](https://gitlab.com/coinmetrics/exporters/defi-exporter/-/jobs/4605030225#L1084) at org.sonarsource.kotlin.plugin.KotlinSensor$visitFile$1.invoke(KotlinSensor.kt:258)
We also see lots of:
Failed to prepare download of the sensor cache
org.sonar.api.utils.MessageException: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator
in the logs which is not consistent with the fact that the report was uploaded successfully i.e. it can’t be that these are not set.
We’re using the following docker image: gradle:8.2.0-jdk11-jammy instead of one from SonarCloud docs (gradle:alpine) but I don’t think this is the cause of problem.
What would you suggest to advance this?
I also tried to login to the support channel but it does not appear to allow logins using my private or corporate email which I don’t quite understand as we are a customer.
Thanks in advance,
Dalen