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.).

  • Would Docker or Vagrant be help in creating test machine for our enterprise product
  • docker compose and jenkins
  • Is it possible to run kubernetes as a docker container?
  • Running interactive commands in docker in Python subprocess
  • Azure Docker Container Service Multiple Instances
  • Bluemix create container group linking to another container
  • 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?

  • Docker and inconsistent IP addresses from host
  • How can I change docker network ip address in Mac
  • Connect to MySQL server from php with Docker
  • How to set the Docker IP the same as your computer (local) IP address
  • docker swarm for bare metal : ubuntu
  • Accessing services on the Docker host
  • 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:

    • 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.