Search code examples
gradlew

Optimizing installation size for gradle wrapper


We are working on a a system that uses cloud runner, where we have a tech like Spring + Gradle plus Mongo.

The system is containerized and runs on cloud-run in gcp. However, gcp has a hard limit of 2gb on container size, which we are trying to fit into, as of now.

Upon deeper investigation, I found that, the gradle wrapper that we use downloads at least 170mb extra than what we needed.

It includes following -

  1. It contains documentation, which is not needed while running a build via wrapper.
  2. It does not delete the zip file after extracting the same..

Together it counts to 270 mb, which quite big for us.. What I want to know is, Is there any wrapper configuration OOTM that will help me avoid these extra files being downloaded on our system?


Solution

  • It seems you used the Gradle distribution type "all", which includes source code and the Gradle documentation (e.g., for IDE support -- source).

    Since you run the Gradle wrapper in the cloud, you probably do not require IDE support: Use distribution type "bin". At least in latest versions of Gradle (version 7) this is the default, but you can still be explicit to make sure:

    # gradle wrapper --gradle-version 7.0.2 --distribution-type bin
    

    The size difference is about 200 MB:

    # du -hs ~/.gradle/wrapper/dists/gradle-7.0.2-{all,bin}                      
    438M    ~/.gradle/wrapper/dists/gradle-7.0.2-all
    229M    ~/.gradle/wrapper/dists/gradle-7.0.2-bin
    

    Gradle still keeps the zip-file, so you will have to delete that manually.