3

I have a task in which I am executing a command. And I need to change which parameters are passed to the command depending on whether I do ./gradlew --debug myTask or ./gradlew myTask.

I thought that it would be as simple as doing: project.logger.isEnabled(LogLevel.DEBUG), but this returns false even when --debug is passed to Gradle.

-=-=-=-=-=-=-=-=-=-

It seems that you are both correct. I was making an invalid assumption that the main Gradle process would pass its debug flag information to the tooling API, which turned out to be incorrect. The issue was that I needed to pass an additional --debug flag to the tooling API process.

GreenSaguaro
  • 2,968
  • 2
  • 22
  • 41

2 Answers2

5

You could use

if (project.gradle.startParameter.logLevel.name() == 'DEBUG')

@see StartParameter.getLogLevel()

lance-java
  • 25,497
  • 4
  • 59
  • 101
3

The following build.gradle works just fine:

println "LOL ${logger.isDebugEnabled()}"

Try running just gradle and gradle -d or gradle --debug

Opal
  • 81,889
  • 28
  • 189
  • 210
  • I will give it a shot. I was trying a bunch of different things. With and without project, etc. Not sure if it makes a difference, but I am doing this not from build.gradle, but rather in a task extending DefaultTask. – GreenSaguaro Apr 12 '17 at 06:40
  • @kurzweil4 it possibly makes a difference - I mean script evaluation may play a role here. – Opal Apr 12 '17 at 06:46
  • 1
    You are both right, but Lance's answer is more specific. Thank you for the response! – GreenSaguaro Apr 12 '17 at 22:54