Setting IntelliJ compiler args in Gradle

随声附和 提交于 2021-02-18 21:58:44

问题


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?


回答1:


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"
        }
    }
}



回答2:


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).



来源:https://stackoverflow.com/questions/42916687/setting-intellij-compiler-args-in-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!