paketo-buildpacks / bellsoft-liberica

A Cloud Native Buildpack that provides the Bellsoft Liberica implementations of JREs and JDKs
Apache License 2.0
74 stars 18 forks source link

Does not detect the java version from the POM #711

Closed novellat closed 2 months ago

novellat commented 2 months ago

Seems you need to supply it with BP_JVM_VERSION. Why doesn't it just read it from the POM?

Expected Behavior

It shuold determine the java version from the POM. for example from the configuration

<properties>
    <java.version>21</java.version>
        <maven.compiler.source>21</maven.compiler.source>
       <maven.compiler.target>21</maven.compiler.target>
</properties>

Current Behavior

uses Java 17 by default, or waits for the env variable

Possible Solution

Just read the POM.

Steps to Reproduce

Motivations

We want the buildpack to build whatever is provided. This won't build Java 21 projects in some cases, because it simply uses Java 17, if no parameter is supplied...

dmikusa commented 2 months ago

We do not read the POM because it is unfortunately not that simple. POMs can be very complicated when you take into consideration parent POMs and the wide variety of ways to do things in them (for example, the properties you're referencing are a convention from Spring Boot, not something that will always exist in that exact format).

There is only one 100% reliable way to parse them and that is to let Maven do it. That is problematic though because Maven isn't installed at the time when we need to know which Java version to install (it creates a circular dependency).

Anyway, if you're building with Spring Boot build tools, it will handle this automatically. If you're building with pack, you could add a small shell script to run maven and extract that value and set BP_JVM_VERSION correctly. Either way would pull from your pom.xml.

novellat commented 2 months ago

Thanks for the reply. I'm not well-versed in the Java env, so I didn't know this. Yea, I think that's the thing we'll do. Maybe a feature suggestion, you might want to implement this detection heuristics (by some flag BP_SMART_JAVA_VERSION_DETECTION) based on a similar script, or just make it explicit in the docs that the version needs to be supplied.

Either way, thank you for your answer and have a nice day!