Gradle console output cleared after error

Answered

I think it's a known issue that System.out doesn't display in the console window for gradle projects, in some cases. A particularly bad case is when an error occurs. IDEA clears the console after the error, so you can't see what the error was.

Is there a solution to this?

0
7 comments

Hi, please provide more details about the problem. Is it specific to a single project?

What kind of project is it? Can you share it so that I can try reproducing the issue?

Are you aware of any particular issues on YouTrack opened with regards to this problem?

0

It is a gradle project. Whenever, I run a main java class and it results in an exception, the console window is then cleared, so you can't see what the exception was.

If I debug the program and use printStackTrace, and step over it, it does print in the console window. So, with effort that is a way to see what the problem was. But, it would be much more useful if the console output was preserved.

If I the step over a throw statement, there is an entry that just displays just the message of the top-level exception. Below that is the exit result, with the console window only containing the ending lines that gradle prints. Much less useful that console output.

0

Please provide a self-sustained code sample, the entire output of the console window after you run it, and a screenshot of the corresponding Run/Debug Configuration (Run | Edit Configurations).

0

I hope this is what you are asking for. This is the code:

package bork;

public class Geborken {

    public static void main(String... args) throws Exception {
        try {
            System.out.println("Text to appear in console output.");
            throw new Exception("Bork bork.");
        } catch (Exception ex)  {
            ex.printStackTrace();
            throw ex;
        }

    }
}

This is build.gradle (it's gradle 7.5):

plugins {
    id 'java-library'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8);
    }
}
repositories {
    mavenCentral()
}

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:31.0.1-jre'
}

testing {
    suites {
        test {
            // Use JUnit Jupiter test framework
            useJUnitJupiter('5.8.2')
        }
    }
}

This is the entire console tab contents, after running the program:

Execution failed for task ':Geborken.main()'.
> Process 'command '/opt/jdk8u332-b09/bin/java'' finished with non-zero exit value 1

* 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.

 

0

Thanks, I'll try to reproduce this and get back to you.

0

Try checking the output up one level:

1

Ah. I didn't think to look there. Ok. That works.

0

Please sign in to leave a comment.