Setting IntelliJ compiler args in Gradle
Asked Answered
D

2

8

I need to add the -parameters java compiler parameter for my tests to succeed. I can do this in gradle already for ./gradlew build to work, or manually by adding -parameters under IntelliJ Settings > Build.. > Compiler > Java Compiler > Additional command line parameters: so they work in the IDE, but I don't want everyone who checks out this repo to have to do a manual step.

My .ipr file does show

<component name="JavacSettings"> <option name="ADDITIONAL_OPTIONS_STRING" value="-parameters" /> </component>

after setting it manually, but is it possible to configure the idea plugin in gradle so ./gradlew idea just does all the work?

Disaccustom answered 21/3, 2017 at 1:7 Comment(0)
K
2

It's possible to do that with the new "Proof-of-concept" plugin from JetBrains: gradle-idea-ext-plugin with following configuration:

idea.project.settings {
    compiler {
        javac {
            javacAdditionalOptions "-parameters"
        }
    }
}
Kiln answered 28/11, 2018 at 14:17 Comment(4)
I tried that and keep on a getting a value is null when in a multimodule project. Have you run it in that context? github.com/JetBrains/gradle-idea-ext-plugin/issues/58Accepter
@PeterKahn I actually use that in multi module project. Javac options are set on every Gradle sync.Kiln
Interesting. I wonder if I'm on too old or too new a version of gradle because I tried a simple example which is what I put up in the #58 issue. So, what version of gradle and plugin?Accepter
I am using gradle composite build. Is it possible to set different compiler args for different modules?Mathur
F
0

You can modify the ipr file as XML and add the component node. The official documentation has an example how to do this:

idea.project.ipr {
    withXml { provider ->
        provider.node.component
                .find { it.@name == 'VcsDirectoryMappings' }
                .mapping.@vcs = 'Git'
    }
}

But you will be limited to the IDEA file project structure (as opposed to the .idea directory structure).

Favela answered 21/3, 2017 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.