Gradle and Java 8 named method parameters (-parameters flag)

Posted: 2016-06-30 in Tricks & Tips
Tags: , , ,

Get know how to enable named method parameters support in a Gradle project


Java 8 has introduced (among others) an ability to get a method parameter name at runtime. For backward compatibility (mostly with existing bytecode manipulation tools) it is required to enable it explicitly. The operation is as simple as an addition of a -parameters flag to a javac call in hello world tutorials. However, it turns out to be more enigmatic to configure in a Gradle project (especially for Gradle newcomers).



To enable support for named method arguments it is required to set it for every java compilation task in a project. It can be easily attained with:

tasks.withType(JavaCompile) {
    options.compilerArgs << '-parameters'

For multi-project build the construction has to be applied on all the subprojects, e.g.:

subprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << '-parameters'


For me as a Gradle veteran and Gradle plugins author construction withType and passing different compilation or runtime JVM options is a bread and butter. However, I needed to explain it more than once to less Groovy experienced workmates, so for further reference (aka “Have you read my blog?😉 ) I have written it down. As a justification for them I have to agree that as a time of writing this blog post the top Google results point to Gradle forum threads containing also “not so good” advises. Hopefully my article will be positioned higher🙂.

Tested with Gradle 2.14 and OpenJDK 1.8.0_92.

Image credits:

  1. […] >> Gradle and Java 8 named method parameters (-parameters flag) [] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s