Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maven plugin should not use staged runtime #814

Open
vpa1977 opened this issue Aug 16, 2024 · 8 comments
Open

maven plugin should not use staged runtime #814

vpa1977 opened this issue Aug 16, 2024 · 8 comments
Labels
Bug Something isn't working

Comments

@vpa1977
Copy link
Contributor

vpa1977 commented Aug 16, 2024

Bug Description

Maven plugin tries to use staged Java runtime instead of the one installed as the build package.
This causes a subsequent build failure due to runtime missing necessary modules to compile Java files.

To Reproduce

  1. rockcraft pack
    Build succeeds
  2. rockcraft pack
    Build fails

part yaml

name: maven-sample-chisel
version: 0.0.1
summary: Sample Maven-based chiselled rock
description: |
  This image is a sample maven application
  using openjdk-21-jre-headless slices

base: bare
build-base: [email protected]

run-user: _daemon_

platforms:
  amd64:

services:
  test:
    override: replace
    summary: Service summary
    command: /usr/bin/java -jar /jars/sample-0.0.1-SNAPSHOT.jar
    startup: enabled

parts:
  application:
    plugin: maven
    source: ./sample
    source-type: local
    build-packages:
      - maven
      - openjdk-21-jdk-headless

  runtime:
    plugin: nil
    source: https://github.com/vpa1977/chisel-releases
    source-type: git
    source-branch: 24.04-openjdk-21-jre-headless
    build-packages:
      - ca-certificates-java
    override-build: |
      chisel cut --release ./ --root ${CRAFT_PART_INSTALL} \
        base-files_base openjdk-21-jre-headless_security \
        openjdk-21-jre-headless_management \
        openjdk-21-jre-headless_jfr
      mkdir -p ${CRAFT_PART_INSTALL}/etc/ssl/certs/java/
      cp /etc/ssl/certs/java/cacerts ${CRAFT_PART_INSTALL}/etc/ssl/certs/java/cacerts
      java_bin=$(find ${CRAFT_PART_INSTALL} -name java -type f -executable)
      ln -s --relative $java_bin ${CRAFT_PART_INSTALL}/usr/bin/java

Relevant log output

2024-08-16 15:15:30.892 :: ## Plugin environment
2024-08-16 15:15:30.892 :: ## User environment
2024-08-16 15:15:30.892 :: 2024-08-16 15:15:29.753 plugin validation command: 'mvn --version'
2024-08-16 15:15:30.892 :: 2024-08-16 15:15:29.861 executed mvn --version with output �[1mApache Maven 3.8.7�[m
2024-08-16 15:15:30.892 :: Maven home: /usr/share/maven
2024-08-16 15:15:30.892 :: Java version: 21.0.4, vendor: Ubuntu, runtime: /root/stage/usr/lib/jvm/java-21-openjdk-amd64
2024-08-16 15:15:30.892 :: Default locale: en, platform encoding: UTF-8
2024-08-16 15:15:30.892 :: OS name: "linux", version: "6.8.0-40-generic", arch: "amd64", family: "unix"
2024-08-16 15:15:30.892 :: 2024-08-16 15:15:29.861 Executing PosixPath('/root/parts/application/run/build.sh')
@vpa1977 vpa1977 added the Bug Something isn't working label Aug 16, 2024
@vpa1977 vpa1977 changed the title maven plugin should not used staged runtime maven plugin should not use staged runtime Aug 16, 2024
@vpa1977
Copy link
Contributor Author

vpa1977 commented Aug 16, 2024

See #813 for the sample project.

@lengau
Copy link
Contributor

lengau commented Aug 17, 2024

I'm not sure we can do this without breaking backwards compatibility, but maybe we can provide an option about staging a JRE (defaulting to True)?

@cmatsuoka what do you think?

@vpa1977
Copy link
Contributor Author

vpa1977 commented Aug 18, 2024

The issue with the staged runtime is that the error message from the build is misleading - release X is not supported. and there is no way to make maven use the desired JDK.
It would be nice to have java_home property to point it to the right Java that should default to build-package JDK if present.

@vpa1977
Copy link
Contributor Author

vpa1977 commented Aug 30, 2024

The root cause is stage path being prepended to the PATH:

/root/stage/usr/bin:/snap/rockcraft/x1/libexec/rockcraft:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This forces Java plugins to use staged runtime.

@tigarmo
Copy link
Contributor

tigarmo commented Sep 26, 2024

The stage dir is always prepended to the PATH, yes. That's typically how one can use a custom version of build tools. It's too late to change this now but we can discuss alternatives for 26.04.

What's really interesting to me, though, is that Maven is picking up the staged Java even though it's just the runtime, and not a full JDK. That looks like a bug we might be able to fix. @vpa1977 do you know if there's any way to control how Maven finds the Java to use?

@vpa1977
Copy link
Contributor Author

vpa1977 commented Sep 26, 2024

What's really interesting to me, though, is that Maven is picking up the staged Java even though it's just the runtime, and not a full JDK. That looks like a bug we might be able to fix. @vpa1977 do you know if there's any way to control how Maven finds the Java to use?

Maven checks JAVA_HOME and then the search path.
Note: this is not Maven-specific. Gradle will use the search path and ignore JAVA_HOME (kind of).

@tigarmo
Copy link
Contributor

tigarmo commented Sep 26, 2024

so in this case would it be enough to set JAVA_HOME in the part's build-environment?

@vpa1977
Copy link
Contributor Author

vpa1977 commented Sep 27, 2024

so in this case would it be enough to set JAVA_HOME in the part's build-environment?

This would be sufficient for maven plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants