The package maven
depends on default-jre-headless (>= 2:1.7) | java7-runtime-headless
(according to sudo dpkg -I /var/cache/apt/archives/maven_3.5.2-2_all.deb
). I noticed the following behavior on Ubuntu 18.04 running inside Docker (image docker:18.04
):
apt-get update && apt-get install --yes openjdk-8-jdk
apt-get install --yes maven
install OpenJDK 8 JDK (including JRE) and then only Maven because a JRE is already provided. However both
apt-get update && apt-get install --yes maven openjdk-8-jdk
and
apt-get update && apt-get install --yes openjdk-8-jdk maven
cause OpenJDK 11 JRE to be installed because it's the default JRE. Why does apt-get install
not scan the package list to check whether dependencies are provided? I'll go so far and say that apt-get
usually does that, even though I find no info about it.
One overview of the command and results (with a project which requires JDK 8 through the maven-enforcer-plugin
) is provided at https://gitlab.com/krichter/maven-enforcer-plugin-docker/pipelines/26241321. I have no reason to believe that the behavior on my desktop Ubuntu 18.04 is different.
I'm looking for an explanation of the described scenario and maybe a hint to a configuration which adapt the package list parsing. This is not a problem for me and I need no workaround.
In my opinion this behavior is sub-optimal since it's more intuitive that the explicit specification of a package fulfilling a dependency of a package in the same list overrides the need to install an implicit default. If you'd want both OpenJDK 8 and 11 installed you'd specify both in the package list. Maybe someone else had this idea and filed an enhancement request (probably to Debian rather than Ubuntu). I'd the happy about the link.
It's probably a result of how apt walks the dependency tree. Looking at the
maven
package details, we see:If
openjdk-8-jre-headless
is already installed, then thejava-7-runtime-headless
dependency is fulfilled and apt doesn't need to install anything additional there.On the other hand, if nothing satisfying
java-7-runtime-headless
is installed, then apt will go first fordefault-jre-headless
, since none of the packages named for installation fulfills either dependency, and JDK 11 gets installed. Since otherwise the package fulfilling this dependency is buried in the dependency of another package, we have a Catch-22 when it comes to creating the list of packages for installation.If you explicitly name one of the packages providing
java7-runtime-headless
for installation, apt will work as you want:The solution provided by muru is not complete IMO. When you run
you have only JRE, not JDK. To install OpenJDK 8 version with Maven without installing OpenJDK 11 I modified apt command