Home > Enterprise >  Installing maven using `apt-get install` overwrites Java8 with Java11
Installing maven using `apt-get install` overwrites Java8 with Java11

Time:12-11

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?

CodePudding user response:

In my situation, I found I could stop Java11 from being installed by putting using the following 3 packages on hold:

RUN apt-mark hold default-jdk  \
  && apt-mark hold default-jre \
  && apt-mark hold default-jre-headless \
  && apt-get install -y maven

At least for my situation (Corretto Java8 JDK installed on a Ubuntu 20 image) that marking these packages as on hold kept the maven install from updating the java version to 11.

CodePudding user response:

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.

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 with apt-get. You can simply download Maven with wget and unpack it.

Here is a Dockerfile example for this:

FROM adoptopenjdk/openjdk8:debian-slim

RUN apt-get update && apt-get install -y wget && \
    wget https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
    tar -xvzf apache-maven-3.8.4-bin.tar.gz && \
    rm apache-maven-3.8.4-bin.tar.gz

ENTRYPOINT [ "/apache-maven-3.8.4/bin/mvn", "--help" ]`

Or you could simply use a Maven image with Java 8:

FROM maven:3.8.4-jdk-8

ENTRYPOINT [ "mvn", "--help" ]
``
  • Related