SonarRunner with gradle: Fail to download libraries from server - gradle

I have updated Sonar to the 4.5.1 LTS version, and now in my gradle task i have got the following error and can't fix it:
Fail to download libraries from server
build.gradle with sonar runner
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://sonar:9000"
property "sonar.login", ""
property "sonar.password", ""
property "sonar.jdbc.url", "jdbc:mysql://sonar"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
property "sonar.profile", "sonar"
property "sonar.projectName", "sonar"
property "sonar.language", "java"
property "sonar.sources", "src/main/java"
property "sonar.binaries", "build";
}
}
i've tried to write this property, but nothing happend:
toolVersion = '2.3' // default

Recent Sonar versions require Gradle 2.2. (2.1 might also work but I'm not sure.)

As a work around, i've installed sonar-runner, and analyzing my gradle project now via sonar-runner 2.4.

As said before, recent SonarQube versions need Gradle 2.2 on client side.
If you cannot or do not want to update your used Gradle version, you can easily copy the Gradle Sonar Runner plugin to your buildSrc project with some slight modifications to not depend on Gradle Injection which does not work for a custom plugin.
I just did this for our project that is still using Gradle 1.12 and it works great.

Related

How to configure sonar.junit.reportPaths

I have tried severally to configure this sonarqube property sonar.junit.reportPaths within Gradle but still get the same error message.
Gradle version -> 6.7.1
SonarQube Server version -> 8.9 (docker image)
Java version -> openjdk 11.0.2
Intellij version -> 2021.1.2
My Sonarqube Gradle configuration is as below:
plugins {
id 'java'
id 'jacoco'
id "org.sonarqube" version "3.3"
id 'org.jetbrains.kotlin.jvm' version '1.5.20'
}
sonarqube {
properties {
property 'sonar.projectName', 'Snippets of Java code'
property 'sonar.junit.reportPaths', 'build/test-results/test'
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/test/jacocoTestReport.xml'
property 'sonar.inclusions', '*.java,*.kt'
}
}
jacocoTestReport {
reports {
xml.required = true
csv.required = false
}
}
I still get the message below:
Resource not found: com.sammy.service.JavaFareTest under the directory /Users/samuelifere/IdeaProjects/codingChallenges while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly
Resource not found: com.sammy.model.JavaCardTest under the directory /Users/samuelifere/IdeaProjects/codingChallenges while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly
I read several stackoverflow pages such as these:
1, 2 but still didn't help in resolving my issue. Any help would be much appreciated, so it can properly find the resources.
The command I use to run to run this through Gradle is:
./gradlew clean build jacocoTestReport sonarqube

Is it possible to override sonar.modules in the sonarqube gradle plugin?

I'm trying to set up sonar analysis across a non-standard multi-project directory structure with a root project to aggregate all the sonar data.
Using sonarqube runner, I've tried to set the property sonar.modules with all the sub-projects (which are not in child directories), but the plugin seems to override the property with erroneous default values that cause my build to fail.
The overwrite seems to happen in this java class : https://github.com/SonarSource/sonar-gradle/blob/master/src/main/java/org/sonarqube/gradle/SonarQubePlugin.java on line 190.
Is there a way around this problem?
I have not tried, but looking at how other properties(sonar.projectKey, sonar.projectName, sonar.projectVersion) within the same addGradleDefaults method are begin set, Did you try the same pattern followed for configuring the other properties per SonarQube plugin documentation ?
FYR, Here is the link from SonarQube on How to use the plugin and or override the default values within the gradle build script. http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle
Here is the code snippet
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.projectName", "My Project Name"
property "sonar.projectKey", "org.sonarqube:java-gradle-simple"
}
}

Connect SonarQube (4.5.4 ) with Gradle (2.1) throws HTTP 400

I want to connect Gradle (Version 2.1) with SonarQube (4.5.4 LTS), but there is this Exception
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':<myProject>:sonarAnalyze'.
> java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:9000/batch/
* Try:
Run with --debug option to get more log output.
Relating to this Post it shoud be possible, and here is maybe the Bug with the related workaround.
But how can I use it? Unpacking the zip into the Project and importing the lines from the build.gradle from the zip-file doesn't work for me :( (makes no difference).
The sonar-configuration in build.gradle:
apply plugin: "sonar"
sonar {
server {
url = "http://localhost:9000"
}
database {
url = "jdbc:mysql://localhost:3306/sonar"
driverClassName = "com.mysql.jdbc.Driver"
username = "sonar"
password = <myPassword>
}
}
apply plugin: 'sonar-runner'
sonarRunner {
sonarProperties {
property 'sonar.host.url', 'http://localhost:9000'
}
}
Thanks in advance :)
PS: Gradle and Sonarqube are working fine.
Sonar Plugin is deprecated:
You may wish to use the new Sonar Runner Plugin instead of this
plugin. In particular, only the Sonar Runner plugin supports Sonar 3.4
and higher.
Use the Sonar Runner Plugin only
apply plugin: "sonar-runner"
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000"
property "sonar.jdbc.url", "jdbc:mysql://localhost:3306/sonar"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "<myPassword>"
}
}
In fact the two SonarQube plugins part of the Gradle distribution are now deprecated. See the following official message from the Gradle team: https://twitter.com/gradle/status/613530568655966208. Only the new one directly maintained by the SonarSource team should be used : http://docs.sonarqube.org/display/SONAR/Analyzing+with+Gradle

Gradle cannot resolve dependencies for Sonar-Runner

I am trying to set up the Sonar-Runner with my existing gradle project. I am using Sonar-Runner 2.4 Gradle 2.2.1 and our Sonar server is 4.3.1. When I run gradle sonarRunner I get the following error:
Could not resolve all dependencies for configuration ':sonarRunner'.
Cannot resolve external dependency org.codehaus.sonar.runner:sonar-runner-dist:2.4 because no repositories are defined.
I do have the artifact "org.codehaus.sonar.runner:sonar-runner-dist:2.4" in my nexus server that is set up in my build.gradle file. Does anyone have any intuition about this error? I have googled it extensively and been stuck on this for a couple of hours now.
My build.gradle for the sonar runner is very simple:
apply plugin: 'sonar-runner"
sonarRunner{
toolVersion = '2.4'
sonarProperties{
property "sonar.host.url", "$sonarHost"
}
}
It seems no repository is declared for the project you want to use with the sonar-runner plugin.
You might have configured repositories for buildscript or for other projects only (in your multiproject build?)
To resolve the sonar-runner you need to configure a repository where it could be resolved from. You might have a coorporate repository in your company or you could use public ones like mavencentral or bintray. to declare for example the jcenter repository to resolve the sonar-runner. just add the following to your build script:
repositories {
jcenter()
}

Can sonar.sources be configured through SonarQube UI so that Eclipse users pickup the same configuration?

By default SonarQube will not analyse test source sets, so I have configured build.gradle's sonarRunner task as below.
I then discovered that I can setup the exclusions list in SonarQube > Configuration > Settings > Exclusions so that this setting can be shared by the eclipse plugin.
Can sonar.sources and similar properties be configured through Sonars UI for a project so that Eclipse users pickup the same configuration? If not is there another way?
build.gradle
apply plugin: 'sonar-runner'
sonarRunner {
sonarProperties {
...
property "sonar.sources", "src/main/java, src/test/java"
property "sonar.tests", ""
property "sonar.binaries", "build/classes/main, build/classes/test"
property "sonar.exclusions", "<list here>"
}
}
No, this is not possible.
If you want to analyse your Gradle-based project in Eclipse, I can understand that you feel like this is a problem because there's no built-in support for Gradle projects in the SQ Eclipse plugin. Still, what you can do is to duplicate those properties in the SonarQube properties of the Eclipse project (righ-click on the project => "Properties > SonarQube > Preview Analysis Properties").

Resources