Not able to connect sonar central server from a gradle springboot project - sonarqube

I am trying to run sonar central server https://sonar.company.com/ from my gradle project. i am getting below error "SonarQube server [https://sonar.company.com] can not be reached".
My Gradle task
sonarqube {
properties {
property "sonar.projectKey", "key"
property "sonar.host.url", "https://sonar.company.com"
property "sonar.login", "347823rywejfsdjhfjsd8fsdjhf"
}
}

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

Read SonarQube properties of gradle plugin

I'm using Gradle 2.14.
I'd like to read the report-task.txt generated by the SonarQube Gradle plugin. For this purpose I need to get the location of this file which is stored in
sonarqube {
properties {
sonar.working.directory "..."
}
}
I want to access this property from outside the sonarqube plugin, i.e. I'm writing a gradle task that runs after the sonar task. This tasks needs to process the report-task.txt located in sonar.working.directory.
Is is possible to access the properties of a gradle plugin?
The task sonarqube exposes all of the defined properties:
plugins {
id "org.sonarqube" version "2.0.1"
}
sonarqube {
properties {
property "sonar.working.directory", "..."
}
}
task printSonarqubeProperty {
doLast {
println "${project.tasks['sonarqube'].properties['sonar.working.directory']}"
}
}

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

SonarRunner with gradle: Fail to download libraries from server

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.

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