Build Java Gradle project within a Docker container?
We have a Java project built with Gradle, and it requires Java 8 etc. Developers have different Java versions on their machines (different projects, IDEA has always been picky about Open JDK, but we use it to run our apps) and we would like to easily be able to build with the correct Java version.
The idea is to use Docker for the task, i.e. start a docker container with the correct Java version and use it for the build (compile, test, assemble etc.).
Is this a good idea? How would I go about it? For example, do I tell Gradle to start the container, and tell it to use its javac? Or do I start the container, mount a volume with the project code, and build using Gradle in that container? This would have the disadvantage that people need to start a container first, but I guess it could be scripted.
Does anybody do something like this?
One Solution collect form web for “Build Java Gradle project within a Docker container?”
If the goal is to standardise the build, then you should use a build automatisation software:
Also, if your gradle project must be run with a specific version, you may enforce it: How do I tell Gradle to use specific JDK version?
I wouldn’t use docker for that.