gradle

How can I make "gradle --stacktrace" the default?


Is there a way I can set --info or --stacktrace via gradle.properties?

I currently have a gazillion build scripts that end up invoking gradle at some point, and I would like to standardize the error handling behavior across the board.


Solution

  • Not in gradle.properties but in build.gradle itself. Add the following piece of code at the very beginning of the build script:

    import org.gradle.logging.ShowStacktrace
    gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
    throw new RuntimeException('lol')
    

    Or in Android Studio:

    import org.gradle.api.logging.configuration.ShowStacktrace
    gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
    

    It also might be put in init script.

    As pointed out in the comments, from gradle v. 2.14 it will be:

    gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.ShowStacktrace.ALWAYS