How do I create a Gradle Wrapper with custom gradlew/gradlew.bat script?

I have a project where I have locally customized the gradlew.bat script to boostrap Java before checking the JAVA_HOME. I’d like to create a custom Gradle Wrapper jar with this for my other projects, but I can’t figure out how to generate it.

I went so far as to try and crack open the existing Gradle Wrapper jar I was using and manually updating it but I have no idea where the gradlew(.bat) lives in the wrapper jar itself.

Anyone tried to do something like this?

The file is not living in the wrapper jar at all. The wrapper jar just provisions the right Gradle version which then contains the wrapper scripts or templates thereof.

Well, that would explain why none of my updates stick.

So when I call gradle wrapper where does the gradlew/gradlew.bat files get generated from?

It’s part of the distribution configured in the wrapper properties file. So you either need a custom Gradle distribution or you need to add a doLast action to the wrapper task that does your modifications to the standard files.