Gradle crash while building (only in command line)

I have a problem in building with Gradle in Android Studio. I hope it’s the correct place to get help.
I’m posted the question on Stackoverflow too (https://stackoverflow.com/questions/56027251/gradle-crash-while-building-only-in-command-line).

I’ve just upgraded to AndroidStudio 3.4 and Gradle 5.1.1. Gradle Android plugin is 3.4.0 (I’ve also updated some libraries versions used by the project)

Now, I’m able to launch any build command from the Android Studio menu. I’m also able to launch the App onto the device. The App works correctly.

But any gradle command that I launch by command line, even the simple

gradlew help

crashes with the next message:

Creating configuration androidTestFreeDebugAnnotationProcessor

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > Uninitialized object exists on backward branch 135
     Exception Details:
       Location:
         com/android/build/gradle/internal/pipeline/VariantInfoImpl.<init>(Lcom/android/build/gradle/internal/scope/VariantScope;)V @193: goto
       Reason:
         Error exists in the bytecode
       Bytecode:
         0000000: 2b12 3cb8 0034 2a2b b900 4201 0059 1244

Any Invalidate/Restart or reboot does not give help.

Any suggestion?