Created attachment 268746 [details] git diff to change the order of preferred java version I want to get some feedback on a proposal for a change on which JDK is preferred in ports. The idea came from talks in bug #289858 and bug #293467 with ideas about picking a preferred JDK. My proposal patch is attached. The idea explained, I hope I can explain it good enough: Current situation: 1. If no JAVA_VERSION is defined, ports picks JAVA_DEFAULT (currently 21); this is a simple case and is fine as it is. 2. JAVA_VERSION=17, is a specific value. This is clear and fine. 3. JAVA_VERSION=8 11 17 or JAVA_VERSION=17+, for a range java.mk currently picks the lowest number. So here it pick 8 and 17 respectively. New situation: 1. no JAVA_VERSION defined, still JAVA_DEFAULT is used; no changes, this is fine. 2. JAVA_VERSION=17, nothing change, this is fine. 3. JAVA_VERSION=8 11 17 or JAVA_VERSION=17+, for a range java.mk will now pick the highest LTS version. In the example above we will now pick 17 (for 8 11 17) and 25 (for 17+). I think this encourages using modern software on FreeBSD. To me it looks like a relative small change, but a nice step forward. Some notes: - I tested that in the current state of the ports tree all java ports still compile fine. - The USES=java mechanism of looking for installed JDKs still works the same. If you only install jdk22 and no LTS versions it will pick the jdk22. - For port maintainers nothing changes. They can still provide a range of supported Java versions. - If a user want to use a specific JAVA_VERSION they can still override in make.conf.
One thing that's unclear to me still (probably because I don't know the ports system well enough,) is what happens if a port says `JAVA_VERSION= 8 11 17` and OpenJDK 11 is already installed on the system? Ideally I think it should not install a new OpenJDK version, and use 11 as it is supported. As for whether to go with the oldest or newest maching version, I don't really have an opinion. I can see good arguments for both, but can imagine some users want to go with the conservative choice.
(In reply to Harald Eilertsen from comment #1) If you go into a java port like /usr/ports/biology/gatk and type: $ make "JAVA_VERSION=11 17 25" java-debug , you will get output with the decisions made. It shows the possible JDKs, the installed JDKs and the intersection of the two lists and what JDK is chosen for JAVA_PORT_VERSION to actually use. In your example it would indeed choose openjdk 11 because that is already installed.
IMHO, if default is 21 then: "JAVA_VERSION=11 17 25" => 25 "JAVA_VERSION=11 17 21 25" => 21
(In reply to Vladimir Druzenko from comment #3) To me a default is a value used when no value is specified. So the default has no meaning when an actual value is set, IMHO. I think it complicates the algorithm if the default gets two purposes. BTW, java.mk has an undocumented feature that you can set JAVA_PREFERRED_PORTS=JAVA_PORT_NATIVE_OPENJDK_JDK_21. I think this does what you are looking for. /etc/make.conf: JAVA_PREFERRED_PORTS=JAVA_PORT_NATIVE_OPENJDK_JDK_${JAVA_DEFAULT}
(In reply to Ronald Klop from comment #4) But in the example Vladimir gave there isn't a value set too. The port specifies it *can* work with some versions, so if one of the versions it can work with is the default java version it should use that. This also keeps dependencies on non-default java versions down. So I think if you want to keep that JAVA_PREFERRED_PORTS stuff, the default java version should implicitly be the first value on that list. If the user wants to change that value they should set DEFAULT_VERSIONS+=java=… and JAVA_PREFERRED_PORTS should only be for the preferences after the default. But as it is undocumented I have no problem with removing it too. I'm against making _JAVA_PORTS_ALL depend on the presens of JAVA_VERSION and say that it should be _JAVA_PORTS_ALL= JAVA_PORT_NATIVE_OPENJDK_JDK_${JAVA_DEFAULT} \ ${JAVA_PREFERRED_PORTS} \ ${__JAVA_PORTS_ALL} instead, making the default version the unconditional default, then giving the user additional prefered versions (or drop that) and then do the rest of the versions. JAVA_VERSION=8+ and not specifying JAVA_VERSION should mean the same thing.
Created attachment 269337 [details] git diff to change the order of preferred java version Ok, I incorporated the remarks you have. See attachment for new patch. This patch does not change anything about the usage of JAVA_DEFAULT. JAVA_DEFAULT is still used as the preferred jdk, as it is currently. The only thing the patch does is re-order the LTS/non-LTS versions. Java.mk used to prefer the oldest jdk in the JAVA_VERSION range. Now it prefers LTS over non-LTS and it prefers newer versions over older versions. Old: JAVA_DEFAULT=21 JAVA_VERSION=8 11 17 22 => 8 (prefer oldest) JAVA_DEFAULT=21 JAVA_VERSION=17 21 25 => 21 (prefer DEFAULT) JAVA_DEFAULT=21 JAVA_VERSION=22 25 => 22 (prefer oldest) New: JAVA_DEFAULT=21 JAVA_VERSION=8 11 17 22 => 17 (prefer latest LTS) JAVA_DEFAULT=21 JAVA_VERSION=17 21 25 => 21 (no change, prefer DEFAULT) JAVA_DEFAULT=21 JAVA_VERSION=22 25 => 25 (prefer LTS) Taking into account what JDKs are already installed is unchanged and still works as intended. Of the 485 ports with USES=java this change will only affect these 17 ports: biology/gkl: 8 11 databases/cassandra4: 8 11 devel/argouml: 8 11 17 18 devel/gradle5: 8 11 devel/jetbrains-sqlite: 17 21 devel/spark: 8 11 17 java/apache-commons-collections: 8 11 17 18 19 20 lang/kawa: 8 11 math/jacop: 8 11 17 misc/jbidwatcher: 8 11 multimedia/kodi: 8 11 net/activemq: 21 17 net/seda: 8 11 17 21 net/spread-j: 8 11 sysutils/logstash7: 17 11 8 sysutils/rundeck: 11 17 textproc/elasticsearch7: 21 17 11 8 All other java ports already compile with JAVA_DEFAULT or are pinned to a specific jdk. I will do some test runs to make sure everything still compiles. Can you review the patch in the meantime?
(In reply to Ronald Klop from comment #6) That patch seems fine to me. I still think JAVA_PREFERRED_PORTS should be documented and after JAVA_DEFAULT, but that can be done in another PR.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=4bc030c70187e3afd1e7360df1a151704f95375e commit 4bc030c70187e3afd1e7360df1a151704f95375e Author: Ronald Klop <ronald@FreeBSD.org> AuthorDate: 2026-04-08 07:11:51 +0000 Commit: Ronald Klop <ronald@FreeBSD.org> CommitDate: 2026-04-08 07:11:51 +0000 */*: bump portrevision for openjdk dependency change Other USES=java ports use JAVA_DEFAULT or are pinned to a specific version. PR: 293756 biology/gkl/Makefile | 2 +- databases/cassandra4/Makefile | 2 +- devel/argouml/Makefile | 2 +- devel/gradle5/Makefile | 2 +- devel/jetbrains-sqlite/Makefile | 2 +- devel/spark/Makefile | 2 +- java/apache-commons-collections/Makefile | 2 +- lang/kawa/Makefile | 2 +- math/jacop/Makefile | 2 +- misc/jbidwatcher/Makefile | 2 +- multimedia/kodi/Makefile | 2 +- net/activemq/Makefile | 2 +- net/seda/Makefile | 2 +- net/spread-j/Makefile | 2 +- sysutils/logstash7/Makefile | 2 +- sysutils/rundeck/Makefile | 2 +- textproc/elasticsearch7/Makefile | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=ea9b758b76fda040a56a4d48a161804c22b39214 commit ea9b758b76fda040a56a4d48a161804c22b39214 Author: Ronald Klop <ronald@FreeBSD.org> AuthorDate: 2026-03-09 19:19:48 +0000 Commit: Ronald Klop <ronald@FreeBSD.org> CommitDate: 2026-04-08 07:09:59 +0000 Mk/Uses/java.mk: re-order preferred JDK (latest LTS over non-LTS) Old order: 1. JAVA_DEFAULT 2. The oldest JDK in the JAVA_VERSION range. New order: 1. JAVA_DEFAULT (unchanged) 2. The latest LTS from the JAVA_VERSION range is preferred over non-LTS versions. Other existing mechanisms are unchanged. Like looking at what JDKs are already installed. This only affects 17 ports. (see the issue for the list) PR: 293756 Mk/Uses/java.mk | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
Thanks!
This seems to be working pretty well. Ports that depend on openjdk8 went down from 56 to 44 after this change.