Frank Winkler
Frank Winkler

Reputation: 419

Gradle: try to skp sonarqube results in error

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

Upvotes: 0

Views: 334

Answers (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

Upvotes: 1

Related Questions