Inside of my Dockerfile I am trying to simply add Maven to my image that already has a proper version of Java8. As in:
RUN apt-get install -y maven
When I do this, the install for maven
brings along Java11 even thought I simply want to install Maven for the Java8 JDK I already have installed on the box. I am hoping there is some obvious solution to this that is clean and simple. I thought at first that the apt-mark hold
might work, but I cannot figure out the name of the package to hold. For example, I tried
RUN apt-mark hold default-jdk default-jre
&& apt-get install -y maven
It seems very unfriendly of maven to install Java11 without any switch to tell it to either a) install Java8 or do not install Java and just trust that it is installed already.
Any ideas on how to install maven on ubuntu without this issue?
3
Answers
In my situation, I found I could stop
Java11
from being installed by putting using the following 3 packages on hold:At least for my situation (
Corretto Java8 JDK
installed on aUbuntu 20
image) that marking these packages as on hold kept themaven
install from updating the java version to 11.This is not really a Maven problem. When you do
apt-get insall
, the dependencies of the package are installed as well. But in case of Maven, you don’t really need to install it withapt-get
. You can simply download Maven withwget
and unpack it.Here is a
Dockerfile
example for this:Or you could simply use a Maven image with Java 8:
You now have two java versions on your systems. that is not a problem in itself.
Just select the version you want as default using
See https://askubuntu.com/q/1288175 for details.