2

I have a gradle multi module project. I don't have a src directory in the root package, everything is in module.

I am using gradle sonar plugin in dev for deploying to sonar.

See the gradle sonar plugin configuration

I use jenkins for deploying to prod sonar.

This is my sonar-project.properties

# Required metadata
sonar.host.url=http://sonarqube.service.consul
sonar.projectKey=com.domain.api
sonar.projectName=com.domain.api

# Comma-separated paths to directories with sources (required)
sonar.sources=.
sonar.inclusions=**/src/main/java/**/*.java
sonar.exclusions=**/src/main/test/**/*.java
sonar.test.exclusions=**/src/main/test/**/*.java

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

The problem I have is that gradle sonar plugin set sonar.sources dynamically.

I wasn't able to do this on jenkins with the plugin sonar.

Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204

1 Answers1

1

The JENKINS SonarQube plugin, as documented here "lets you centralize the configuration of SonarQube server connection details in Jenkins global configuration."

That means it will inject the environment variable SONAR_HOST_URL to your job (to be used in a mvn build step)

Nothing prevents you to write a groovy script which would set that same environment variable SONAR_HOST_URL to a value dynamically set (for instance, a script using the EnvInject plugin).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok. Appart that EnvInject isn't maintained anymore and have issues when installed with other plugins. How do you set in your `sonar-project.properties` your `sonar.sources` ? Otherwise, how can I know the value of sonar.sources for my project in gradle so I can use it on jenkins ? – Dimitri Kopriwa Apr 23 '17 at 09:27
  • @BigDong you have another approach based on ParametersAction: http://stackoverflow.com/a/25796504/6309. The idea is not to set `sonar-project.properties` but to override some of its properties when the job is executed. Those properties can also be first loaded (by the same grrovy script): http://stackoverflow.com/a/20872275/6309. That way, you can load one originally used by gradle. – VonC Apr 23 '17 at 10:04