Is it possible to obtain Gradle’s module name programmatically in Java code?
I need it to access module’s build files under the
MODULE_NAME/build/intermediates directory, but hardcoding module name is a bad idea.
To get the current’s module name you can just access Gradle’s
Will return, for the module
You can access
project variable inside your build script that is instance of Project. It has various getters like
buildDir and since this is quite common to use them it is documented in user guide.
Alternatively you can find this path if you look for an output of a task that generates files there.
If you need to know this location in your test you can pass it from build script using system property like this:
systemProperty "buildFolder", project.buildDir.absolutePath
BTW: https://github.com/gradle/gradle/blob/master/gradle/idea.gradle#L192 has a trick how to update run configurations in IntelliJ’s workspace with properties that you need for test execution. This can be useful if you run JUnit test inside IJ (without delegating to Gradle).