[CentOS] Installing Maven with OpenJDK 11, without pulling OpenJDK 1.8

Sat Nov 23 23:11:35 UTC 2019
Orion Poplawski <orion at nwra.com>

On 11/23/19 12:24 AM, Mathieu Baudier wrote:
> Hello,
> 
> I am trying to create a container image which will build Java software with
> Maven and Java 11 (rather focussing on CentOS 8 here).
> 
> When installing 'maven' with yum, 'java-1.8.0-openjdk-devel' is installed
> as a dependency. If one then installs 'java-11-openjdk-devel', and use the
> update-alternatives command for java and javac, everything works fine and
> Maven uses Java 11 for the build.
> 
> But I would like to avoid shipping OpenJDK 1.8 with the image, since it
> would uselessly double its size. An approach would be to install Maven
> manually, but it feels better to use the provided package.
> 
> Looking at the spec file, I understand that the 'maven' package requires
> 'java-devel' without explicitly specifying a version.
> Is there some way (configuration, yum option, alternative, etc.) to make
> OpenJDK 11 satisfying this dependency?
> Could the new modules / app stream approach of CentOS 8 help here?
> 
> This is of course a more general RPM / yum question, but I suspect that the
> Java use case is a recurring one, as many of us are currently upgrading
> from 1.8 to 11.
> 
> Thanks in advance for hints, or telling me that there is no way to achieve
> this,

Well, java-11-openjdk-devel only provides 'java-11-devel', so it can't 
satisfy the 'java-devel' dependency.  It does seem like it would be 
possible to produce a maven module and/or stream that was built with 
Java 11 and requires it.  You could also create a shim rpm that required 
java-11-devel and provided java-devel.

I'll also note that maven.spec has:

# Theoretically Maven might be usable with just JRE, but typical Maven
# workflow requires full JDK, so we recommend it here.
%{?fedora:Recommends}%{!?fedora:Requires}: java-devel

Which wasn't updated for RHEL8 (which support weak dependencies).  I 
would suggest filing a bug against RHEL8 to get them to fix that.  Then 
you could simply disable installing "recommends" by default.


-- 
Orion Poplawski
Manager of NWRA Technical Systems          720-772-5637
NWRA, Boulder/CoRA Office             FAX: 303-415-9702
3380 Mitchell Lane                       orion at nwra.com
Boulder, CO 80301                 https://www.nwra.com/