5

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?

4
  • If using a "build server" for developer work is reasonable, then packaging that "build server" in a Docker container so each developer can run their own is also reasonable. Then it requires that developers get comfortable with using Docker, but that is a very useful skill in today's SW development world, so I wouldn't say that is a point against it, rather a point for it. Commented Sep 14, 2016 at 12:39
  • Anyway, this is rather opinion-based question, there is no single right answer, so voting to close with that reason... I wonder if programmers.stackexchange.com already has a bunch of questions like this? Commented Sep 14, 2016 at 12:41
  • @hyde Programmers does not accept opinion-based questions or questions that are polling people. We have the same close reasons as Stack Overflow for these. Commented Sep 14, 2016 at 12:46
  • @ThomasOwens Yeah, then the question would have to be formulated "How do I use Docker for developers building Gradle project". I think that would be more of a PSE than SO question, and also on topic, but not quite sure... Commented Sep 14, 2016 at 12:48

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I used a gradle container to build my springboot java project. You can do something similar.

Dockerfile

FROM gradle:jdk8
COPY . /home/gradle/project
WORKDIR /home/gradle/project
ENTRYPOINT ["gradle"]
CMD ["bootRepackage"]

You can also find information about different gradle containers at https://hub.docker.com/_/gradle/ which shows how you can mount your host directory as volume to the container and build.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.