Search code examples
phpandroidgradleprepare

Gradle triggered from www-data fails sometimes - no detailed error output


I´m triggering my gradle build from my webserver as user www-data with the command

$command = "cd " . $path . "/;./gradlew :app:build  --stacktrace";
exec($command, $output, $error);

Sometimes it failes with

enter image description here

but thats all I get as output, no detailed error with line number like I would get on directly calling the script.

When I do so and run it from command line, it works without any error (in this case)

But even in other cases, when both cases fail, there is no concrete output with the php call.

I have no idea why both ways of running the script seem to behave totally different sometimes and I have no idea how to find any error without any details

What is happening with the output there and how can I enable it?


Solution

  • I´ve solved the issue now.

    The problem was, that the log from Gradle is splitted in the default output, and the error output. In the shell, both is printed by default.

    If you write the output to file with

    ./gradlew assembleRelease --stacktrace > log.txt
    

    you are only logging the default output, not the error output. Therefore you need

    ./gradlew assembleRelease --stacktrace > log.txt 2>&1
    

    to also append the error log to your file.