Crell
Crell

Reputation: 415

What files does gradle wrapper need writeable in order to run?

I'm setting up Gradle with a container-based CI/CD system that has a split build vs run environment. In build, the project's disk is writeable. At runtime, only selected directories are writeable, and those directories are not available during build. It's a clear separation between the two.

The problem I'm running into is that running gradlew build in the build step works, but then running gradlew run in the production environment (on a read-only file system) fails. Specifically, at runtime it tries to recompile the project again, and fails to do so (naturally, because the file system is read-only). But why is it recompiling if it's already been compiled?

I have tried making the build and .gradle directories both runtime-writeable. That does work, and gradlew will then recompile the entire system a second time, write out to those directories, and run. If I then make the build directory read-only again, it continues to work. That to me suggests there's some part of .gradle that needs to be writeable at runtime, but so far I've not found a combination that works other than "everything and everything", which is clearly not desirable. (Doing that one-time build and then fiddling with the directory mounts isn't workable as a production practice, as it's not then a repeatable build.)

I am still fairly new to Gradle so I'm not sure what the cause is. My best theory is that gradlew wanting to re-download gradle initially (even though it's presumably already in .gradle?) is causing it to skip all pre-existing generated files, even if they're present. That's why having one successful build fixes it for future builds, even if the build directory is read-only.

So my question, generally, is what parts of .gradle need to be runtime-writeable in order for a Gradle-built application to work in a read-only environment? Or, more generally, how do I make a Gradle-built application work in a read-only environment, period?

Upvotes: 2

Views: 134

Answers (1)

Vampire
Vampire

Reputation: 38639

Do not use Gradle to run your project at production time. Gradle is a build tool and the run task that is added by the application plugin is only for testing purpose. If you don't want to produce a distributable and then use that at production time, but if you want to run out of the project directory, at least use installDist at build time and then run the project as it is assembled in build/install/... with the generated start scripts.

Upvotes: 2

Related Questions