0

I'm trying to package an RPM that requires any Java version above Java 8. The RPM works fine if there's no Java installed, or if JRE/JDK for 8 is installed. HOWEVER if I install OpenJDK 11, when I install my RPM it will try to install Java 8 again.

How do I get my RPM to detect that there's already a Java 11 installation which should be compatible with my package? I don't want my package to install Java 8 if I have Java 11 already!

I'm running Red Hat 7.5, but this also reproduces in CentOS7. I was able to reproduce this with a simple hello world package:

Name:       hello-world
Version:    1
Release:    1
Summary:    Most simple RPM package
License:    FIXME
Requires:   jre-headless >= 1.8

%description
%prep
%build
cat > hello-world.sh <<EOF
#!/usr/bin/bash
echo Hello world
EOF

%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh

%files
/usr/bin/hello-world.sh

%changelog

Build with:

rpmdev-setuptree
rpmbuild -ba hello-world.spec

Then install OpenJDK11: sudo yum -y install java-11-openjdk

Finally test my package: rpm -i --test <FILE>.rpm gives:

error: Failed dependencies:
        jre-headless >= 1.8 is needed by hello-world-1-1.x86_64

sudo yum localinstall <FILE>.rpm also tries to install Java8.

sudo yum deplist <FILE>.rpm suggests that java-11-openjdk should provide what I need:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.heanet.ie
 * extras: ftp.heanet.ie
 * updates: ftp.heanet.ie
package: hello-world.x86_64 1-1
  dependency: /usr/bin/bash
   provider: bash.x86_64 4.2.46-31.el7
  dependency: jre-headless >= 1.8
   provider: java-11-openjdk-headless.x86_64 1:11.0.ea.28-7.el7
   provider: java-11-openjdk-headless.i686 1:11.0.ea.28-7.el7
   provider: java-1.8.0-openjdk-headless.x86_64 1:1.8.0.201.b09-2.el7_6
   provider: java-1.8.0-openjdk-headless.i686 1:1.8.0.191.b12-1.el7_6
   provider: java-1.7.0-openjdk-headless.x86_64 1:1.7.0.211-2.6.17.1.el7_6

(Not sure why Java 7 is a provider of Java 8 either).

I tried setting requires to jre or java but no luck. Also I tried pre-installing java-11-openjdk-headless specifically, but it made no difference.

It seems like boolean dependencies might fix this, but sadly I can't guarantee my end-users have a recent enough version of rpm installed.

I'm not sure what I could be doing wrong?

How do I set a RPM package to require Java 8 or higher, whose dependencies are satisfied by Java 11?

2

For now, the OpenJDK 11 packages in RHEL 7 and 8 don’t provide java-headless, jre-headless, or any of the unversioned Java packages. (As I understand it, the reason is that OpenJDK 11 isn’t guaranteed to be a replacement for OpenJDK 8 maintaining compatibility in all cases.) This will change when OpenJDK 11 becomes the system JDK; you can try tracking this bug to be notified of changes.

Unfortunately I don’t think there is a way currently to allow an RPM package to depend on jre-headless and be installable with OpenJDK 11 only, without using boolean dependencies (and RHEL 8, effectively). A typical workaround would be to use a file requirement instead of a package requirement, but java-8-openjdk-headless and java-11-openjdk-headless don’t provide a common file which you can depend upon (and I don’t think file requirements can be versioned).

Your query suggests that jre-headless is satisfied by the OpenJDK 11 packages, but that’s because the early-access packages erroneously provided the default packages; so

yum whatprovides jre-headless

lists OpenJDK 8 and OpenJDK 11 packages, but the latter are no longer installable.

  • So it might be a problem with the headless? If I set my Requires to java or jre it still fails to recognise the installed java. Maybe I don't understand why deplist or whatprovides think that Java 11 provides the java/jre package? – jenny Mar 6 at 13:49
  • This affects all the default Java packages. OpenJDK 11 turns up in the query results because of a packaging error in earlier versions of the packages. (See my update for details.) – Stephen Kitt Mar 6 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.