0

I have a gradle script that uses Sonarqube plugin (org.sonarqube). If I let the publish task depends on it, it works fine.

The problem is to run sonarqube only if a condition is true. So I tried (as described in gradle documentation) all of these three statements:

sonarqube.enabled (false)
sonarqube.enabled=false
sonarqube.onlyIf { false }

Each results in an error, here the one I got trying the first statement

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Eclipse\workspace3.6\at.mic.hermes\build.gradle' line: 208

* What went wrong:
A problem occurred evaluating root project 'at.mic.hermes'.
> Could not find method enabled() for arguments [false] on org.sonarqube.gradle.SonarQubeExtension_Decorated@412196.

To be sure to have not typo in the code I tried all statements with the test task, e.g.

test.enabled(false)

and this results (as expeted) in

:test SKIPPED

Any ideas what I made wrong / what must be changed? Thx in advance!

Frank

Frank Winkler
  • 409
  • 6
  • 16
  • Where have you found this documentation about sonarqube.enabled and sonarqube.onlyIf ? Apart if this is a common Gradle feature for all extensions, this is not implemented in SonarQube plugin. – Julien H. - SonarSource Team Jul 27 '16 at 09:47

1 Answers1

1

I think the problem come from a name conflict. There are 2 objects named 'sonarqube':

  • The SonarQube task
  • The SonarQube extension

It seems to not break your build, but here when you write sonarqube.enabled it access to the extension (according to your stacktrace).

The solution is probably to disambiguate using tasks.sonarqube.enabled. See https://docs.gradle.org/current/userguide/more_about_tasks.html#N11143