Search code examples
javagradleintellij-idea

Is it possible to use an init.gradle script in IntelliJ Idea?


I'm using the Gradle wrapper in a project in Idead. I have an init.gradle file in a non-standard location and need to find a way to specify it in Idea. I thought this could be done via the Gradle VM options setting field and entered --init-script /path/to/init.gradle in it, but this throws an Unrecognized option --init-gradle /path/to/init.gradle error when trying to re-import the project.

Is there some other way to do this that I'm not aware of?


Solution

  • You can set Gradle commandline options/arguments from the "Run" configuration panel:

    enter image description here

    If you set this option on the "Templates>Gradle" panel it will apply to all Gradle tasks invocation ( note that you need to execute tasks with Right-click/Run from the Gradle tool window: double-click will not take the option into account..)

    EDIT : another way is to add the commandline options directly in the "Run gradle task" window:

    enter image description here