Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 207
wujek Avatar asked Nov 08 '22 09:11

wujek


1 Answers

If the goal is to standardise the build, then you should use a build automatisation software:

  • Jenkins
  • TeamCity
  • Bamboo
  • ...

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.

like image 105
alexbt Avatar answered Nov 14 '22 20:11

alexbt