Show line number where runtime error occurs in buildSrc


I am trying to learn how to use the buildSrc folder in Gradle but have a question regarding how one can see the line number where a runtime error occurred in a file in buildSrc. I have the following files:

class MyUtility {
    static String greet() {
        int a = 0/0
        return "Hello world!"


apply plugin: 'java'
task showGreeting {
    doLast {

and a settings.gradle file containing only = 'example5'.

When I run ./gradlew showGreeting in my terminal then I get the output

> Task :showGreeting FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\...\build.gradle'  line: 4

* What went wrong:
Execution failed for task ':showGreeting'.
> / by zero

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at

This message only shows where the error occurred in my build.gradle file, but I would like to see on which line in my MyUtility.groovy file that the error occurred. I know that if I add “–stacktrace” then I get this information but it is very verbose. Is there someway to get an error message similar to

* Where:
Build file 'C:\...\buildSrc\src\main\groovy\MyUtility.groovy'  line: 3

so I can quickly get an idea of where the error occurred?

No, you need to use -s to show it.

1 Like