Search code examples
intellij-ideagradlebuild.gradlegradlew

How to work with gradle wrapper, init script, multi project and best with idea


to sum up the components and environment:

so,

Q: How to elegant marriage these components. How can I define an init script to be used in the wrapper of a single repository without affecting other repositories.

I know:

  • init scripts are typical in a "GRADLE_HOME" directory
  • init scripts can be defined per console via -I
    (yes, I read the documentation 😅 )

Problems found:

  • intelliJ doesn't allow to define the -I option in UI
  • anyone needs to checkout and update a seperate repository if you want to share between projects
  • the settings.gradle || gradle.properties file seems not to support any option either

Constraints: (while these are possible answers, they are neither elegant nor fault proof)

  • the desired solution should be applicable for SINGLE projects, and should not be globally applied to all projects on the same computer

Hidden Questions:

  • can I include global gradle settings from an URL so noone needs a clone of the meta-repo??
  • does an URL include do the same as an init script? Or what you can do with initScript what you can't in include?

Solution

  • You can do the following:

    1. Create a custom gradle distribution with the common settings defined in the init script
    2. Configure your projects to use that distribution through the distributionUrl key in the gradle/wrapper/gradle-wrapper.properties
    3. Use regular gradle build from command line/usual import into intellij - it just works

    By the way, there is a gradle plugin for simplifying custom gradle distribution construction