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

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

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

"Could not resolve all files for configuration" after upgrading Gradle

I have a Gradle script that downloads the latest snapshot artifact from a Nexus server. It's been working fine with Gradle 5.4 but doesn't seem to be willing to work after upgrading to Gradle 6.5.
These are the build.gradle contents:
apply plugin: "java"
repositories {
maven {
url "https://somerepo.com/repository/app-snapshot/"
credentials {
username 'a-user'
password 'a-password'
}
authentication {
basic(BasicAuthentication)
}
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
configurations {
component
}
dependencies {
component group: "com.bla.ble, name: "component-name", version: "${version}-SNAPSHOT"
}
task copyComponent(type: Copy) {
from configurations.component
into "/some/local/path"
}
Gradle fails as follows:
Execution failed for task ':copyWorkflow'.
> Could not resolve all files for configuration ':workflow'.
> Could not find com.bla.ble:component-name:3.2.0-SNAPSHOT.
Searched in the following locations:
- https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/maven-metadata.xml
- https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/component-name-3.2.0-20201130.163046-11.pom
Required by:
project :
I've I navigate to https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/maven-metadata.xml this provides a valid metadata file and points to a snapshot that actually has a valid file.
I've then tried downgrading again to Gradle 5.4 and worked OK. I was also trying to find any deprecated options in Gradle 6.x but couldn't find what it makes it fail.
Found the solution through this post: https://discuss.gradle.org/t/how-to-fetch-maven-artifact-without-pom-file-in-gradle-6-0/33836/2
Short history: A breaking change introduced in Gradle 6.x prevents the artifacts from being downloaded if the POM is not present. To go around this requirement, the following needs to be added to the maven definition:
metadataSources {
artifact()
}
More info: https://docs.gradle.org/current/userguide/upgrading_version_5.html?_ga=2.181891495.1612153887.1606754101-263409462.1606754101#maven_or_ivy_repositories_are_no_longer_queried_for_artifacts_without_metadata_by_default

Unable to publish the 'Last Verified' status in PACT Broker

For microservices contract tests, am using PACT with gradle 4.4 and here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'au.com.dius:pact-jvm-provider-gradle_2.12:3.5.22'
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: "au.com.dius.pact"
pact {
serviceProviders {
// You can define as many as you need, but each must have a unique name
UserService {
// All the provider properties are optional, and have sensible defaults (shown below)
protocol = 'http'
host = 'localhost'
port = 8111
project.version = "2.0.1"
hasPactsFromPactBroker('http://10.100.198.200:8113')
}
}
pact {
publish {
version = "2.0.1"
pactDirectory = 'pacts' // defaults to $buildDir/pacts
pactBrokerUrl = 'http://10.100.198.200:8113'
}
}
}
While am able to publish the pact files in the broker and able to see the dependency graphs, 'Last Verified' shows blank after running the pactVerify method. I saw some documentation around 'pact.verifier.publishResults=true' and tried to pass as gradle parameter, but I got an error message saying:
FAILURE: Build failed with an exception.
What went wrong:
Your project is misconfigured, was expecting a 'pact' configuration in the build, but got a String with value '' instead. Make sure there is no property that is overriding 'pact'.
the gradle command I run is:
./gradlew test pactPublish
./gradlew pactVerify -Ppact.verifier.publishResults=true
Please let me know what am I missing, the pact.verifier.publishResults is not accepted
The first thing is your Gradle config is invalid. There should only be one pact block. You have two. Remove the inner one with the publish block in it (but leave the publish block :-D).
If that does not resolve your issue, have a look at https://github.com/DiUS/pact-jvm/issues/738 and see if any of the changes from the comments helps.

sonarqube gradle plugin excluding jacoco integration tests

I'm trying to integrate the sonarqube gradle plugin with the jacoco plugin:
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
My build/jacoco folder contains:
integrationTest.exec
test.exec
However, the sonarqube plugin only recognises the 'test.exec' file:
18:20:45.130 INFO - JaCoCoItSensor: JaCoCo IT report not found: C:\Users\abc3\Downloads\sme-letter\target\jacoco-it.exec
:
18:05:55.609 INFO - Analysing C:\Users\abc3\Downloads\sme-letter\build\jacoco\test.exec
How do I get the sonarqube plugin to recognise 'integrationTest.exec'
Thanks
Mark
I'm not really sure, whether this will work for Gradle plugun, but you may try.
Sonar has a property to specify the name of the integration tests JaCoCo report. This property is called sonar.jacoco.itReportPath (sonar.jacoco.reportPath for unit tests report).
And as far as I know, gradle sonar plugin let you add custom properties to it. So you can change IT report name via properties as follows:
sonarqube {
properties {
property "sonar.jacoco.itReportPath", "build/jacoco/ integrationTest.exec"
}
}
It works for me, but only after merging all jacoco reports into one file AND (important) deleting all other reports
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.junit.reportsPath", "$projectDir/build/test-results"
property 'sonar.jacoco.reportPaths', "${rootProject.buildDir}/jacoco/mergeJacoco.exec"
And you need a merge jacoco task
Task mergeJacoco = tasks.create('mergeJacoco', JacocoMerge, {
doFirst {
delete "$buildDir/jacoco/mergeJacoco.exec"
}
destinationFile(new File(buildDir, 'jacoco/mergeJacoco.exec'))
executionData fileTree('./').include('**/*.exec-partial')
doLast {
delete fileTree('./').include('**/test.exec-partial')
}
})
mergeJacoco.outputs.upToDateWhen { false }
project.tasks["sonarqube"].dependsOn mergeJacoco
mergeJacoco.mustRunAfter ":myProject:test"
And setup jacoco to use those "partial" files
subprojects {
....
jacoco {
destinationFile file("$buildDir/jacoco/test.exec-partial")
append = false
includes = ['com.mypackage.*']
}
}
You'll get unit and IT reports mixed in one, but that's the best I could get

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.

Resources