Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 689
Christian Goetze Avatar asked Apr 30 '15 20:04

Christian Goetze


People also ask

What is the valid syntax to set default in gradle?

Gradle allows you to define one or more default tasks that are executed if no other tasks are specified. defaultTasks 'clean', 'run' tasks. register('clean') { doLast { println 'Default Cleaning! ' } } tasks.

How do I set gradle preferences in eclipse?

After generating the Eclipse project files, you can import the project into a Eclipse workspace. It is important to add the GRADLE_USER_HOME variable in Eclipse: Window->Preferences->Java->Build Path->Classpath Variable. Set it to the path of the ~/. gradle folder in your home directory (e.g. /home/<user_name>/.

Where is gradle build log?

View -> Tool Windows -> Build. There is small "ab" button on the left panel. All gradle logs for current build are there.


2 Answers

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 
like image 129
Opal Avatar answered Sep 20 '22 13:09

Opal


There is another approach where you do not have to edit the build.gradle file because you may not want it so verbose when you run your CI. In addition, you now have to remember to turn it off in CI. So, instead, you can limit to the IDE. If you are using eclipse, you can follow these steps to apply it only to gradle runs within your IDE.

Run -> "Run Configurations" -> Select "Gradle Project" -> Click "Project Settings" tab -> Click "Configure project settings..." link -> Select "Override workspace settings" -> paste "--stacktrace" in "Program Arguments" text field.

The above worked with Spring Tool Suite 4.2.1 which is based on Eclipse 4.11.0.x

like image 29
Rao Pathangi Avatar answered Sep 18 '22 13:09

Rao Pathangi