How to set sourceCompatibility

Of course it does.
If you check with ./gradlew --version then it is only meaningful for running your build also from commandline.
When you run Gradle from IDE, you have to check what you configured in the IDE to run Gradle with in the settings dialog, or by running gradle --version from the IDE.