You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Certain projects might require multiple JDKs during build (e.g., Apache Log4j requires Java 7 and Java 9+ by means of toolchains.xml) and in its current form, that is not possible via setup-java.
It appears to me that adding an optional java-home variable that would determine where to place the java package (which can currently be a jre, jdk, or jdk+fx), overriding the default location, would suffice, right? One would the use setup-java multiple times, once per version.
I'm just wondering what happens if you define two different setup-java steps with different jvm's. Looking sources it set's this extendedJavaHome env variable:
I managed to do this by calling out to the setup-java action for each JDK I have confgured in my toolchain (1.8 and 11) plus once for the JDK I want to run maven with (so 3 times in total).
I'm just wondering what happens if you define two different setup-java steps with different jvm's. Looking sources it set's this extendedJavaHome env variable:
I think that knowing where the JDK was installed is not enough. Some tools expect that java versions to appear at specific file paths. E.g. https://github.com/apache/logging-log4j2/blob/64a5c73636cef24c5cbb70143eef99536944d188/.travis-toolchains.xml#L28 . You could probably do something by symlinking the requested path to where extendedJavaHome points, but that would be messy for the user, and fairly easy for us to do in installer.ts if indicated by setting an optional java-home variable
Hi, I forked this project a while ago to change some things according to my needs. However, there were also additional changes that might be of interest to this project. (Sorry for bringing them up so late. I could have sworn that I commented about this months ago.)
Supporting multiple JDKs was an important feature I needed at that time and the solution I ended up going with is adding an additional input parameter to the action used to specify the "target" environment variable/s with the following semantics:
If the target is not specified explicitly, only JAVA_HOME is set to point to the JDK.
If the target is specified explicitly, it is interpreted as a ; separated list of environment variables that will be set to point to the JDK. (JAVA_HOME is not set to point to the JDK unless the input explicitly contains JAVA_HOME.)
Naturally, this makes it incredibly easy to work with multiple JDK versions since their locations could simply be pointed to by separate environment variables. For example:
This snippet suffices is sufficient to set up a Java 8 and Java 9 for parallel use. Here, 8 will be pointed to by JAVA_HOME, and 9 will be pointed to by JDK_9. (Also, note that this would also fix #21.)
Some tools expect that java versions to appear at specific file paths.
Additionally, should it become necessary to provide control about the directory in which the JDK should reside in (I have not seen the need arise yet), it would be possible to add this as an additional property. In my opinion, controlling the location of the file-system and the environment variables are orthogonal concepts that should not be configurable separately.
If you are interested I would love to get this integrated upstream and I would be happy to contribute.
Since Java 9, jlink can be used to create runtime images that are a subset of the full JDK (and hence OS-specific). For that, the tool needs an unzipped JDK lying around. The cool thing is that it can also create runtime images for a different OS than it is executed on, but then it of course needs that OS's JDK.
So it would be nice if setup-java could not only setup (and configure in toolchains.xml) different Java versions, but also JDKs for different operating systems.
Since Java 9, jlink can be used to create runtime images that are a subset of the full JDK (and hence OS-specific). For that, the tool needs an unzipped JDK lying around. The cool thing is that it can also create runtime images for a different OS than it is executed on, but then it of course needs that OS's JDK.
While we could migrate to v2 and still use AdoptOpenJDK/install-jdk@v1 for the secondary java, it would be nice to have this as an out-of-the-box experience.
Agreed that the concern expressed at the beginning can be addressed by running the action multiple times with different Java versions. As a matter of fact, that is what we ended up doing in Log4j too.
@vy if this is really the solution for this issue, it should mention the snippet on the Help/Readme page, I think this is not that obvious to the usual user.
I am currently working on #276 (see #282 as already mentioned by @laeubi), i.e. directly supporting a generation of the toolchains.xml file mentioned in the initial issue comment. The changes are currently being reviewed and do the following things:
(optionally) generate a toolchains.xml into the default location, i.e. ~/.m2/toolchains.xml, or {{settings-path}}/toolchains.xml if the input value is specified in the setup-java step
add a toolchain with vendor, version, jdkHome, and (custom or default) id for the specified JDK
update any existing toolchains.xml in the specified path to add additional JDKs to it without removing existing entries
Checkout the aforementioned issue and PR for more details or in case you want to leave feedback; specifically before the maintainers decide the implementation is integration-worthy.
Hello everyone. We released a new version of setup-java with support of multiple jdks. For now I'm going to close the issue. If you have any concerns feel free to ping us.
Activity
giltene commentedon Jan 21, 2020
+1
It appears to me that adding an optional java-home variable that would determine where to place the java package (which can currently be a jre, jdk, or jdk+fx), overriding the default location, would suffice, right? One would the use setup-java multiple times, once per version.
jvalkeal commentedon Jan 22, 2020
I'm just wondering what happens if you define two different
setup-javasteps with different jvm's. Looking sources it set's thisextendedJavaHomeenv variable:setup-java/src/installer.ts
Lines 76 to 79 in b52cd69
mprins commentedon Jan 29, 2020
I managed to do this by calling out to the
setup-javaaction for each JDK I have confgured in my toolchain (1.8 and 11) plus once for the JDK I want to run maven with (so 3 times in total).see B3Partners/kadaster-gds2#47
giltene commentedon Jan 29, 2020
I think that knowing where the JDK was installed is not enough. Some tools expect that java versions to appear at specific file paths. E.g. https://github.com/apache/logging-log4j2/blob/64a5c73636cef24c5cbb70143eef99536944d188/.travis-toolchains.xml#L28 . You could probably do something by symlinking the requested path to where extendedJavaHome points, but that would be messy for the user, and fairly easy for us to do in installer.ts if indicated by setting an optional java-home variable
mprins commentedon Jan 29, 2020
see:
https://github.com/B3Partners/kadaster-gds2/runs/415167771?check_suite_focus=true#step:7:14
you can use environment vars in your toolchain
https://github.com/B3Partners/kadaster-gds2/blob/b0cd5c392bc1f48dec11c83c828254a868264467/.github/ubuntu-toolchains.xml#L6-L22
koppor commentedon Feb 27, 2020
This somehow refs #21. Then, one can "just" rely on environment variables.
TheMrMilchmann commentedon May 27, 2020
Hi, I forked this project a while ago to change some things according to my needs. However, there were also additional changes that might be of interest to this project. (Sorry for bringing them up so late. I could have sworn that I commented about this months ago.)
Supporting multiple JDKs was an important feature I needed at that time and the solution I ended up going with is adding an additional input parameter to the action used to specify the "target" environment variable/s with the following semantics:
JAVA_HOMEis set to point to the JDK.;separated list of environment variables that will be set to point to the JDK. (JAVA_HOMEis not set to point to the JDK unless the input explicitly containsJAVA_HOME.)Naturally, this makes it incredibly easy to work with multiple JDK versions since their locations could simply be pointed to by separate environment variables. For example:
This snippet suffices is sufficient to set up a Java 8 and Java 9 for parallel use. Here, 8 will be pointed to by
JAVA_HOME, and 9 will be pointed to byJDK_9. (Also, note that this would also fix #21.)Additionally, should it become necessary to provide control about the directory in which the JDK should reside in (I have not seen the need arise yet), it would be possible to add this as an additional property. In my opinion, controlling the location of the file-system and the environment variables are orthogonal concepts that should not be configurable separately.
If you are interested I would love to get this integrated upstream and I would be happy to contribute.
jonashackt commentedon Jan 7, 2021
I wonder if the matrix strategy is already everything we need here (as also stated on stackoverflow). I implemented this in codecentric/cxf-spring-boot-starter's action configuration in the .github/workflows/maven.yml:
mprins commentedon Jan 7, 2021
No, this only installs 1 java version for one build, not multiple java versions for 1 build
jonashackt commentedon Jan 8, 2021
Ah I see. Didn't get that first, maybe the issue could be refrased a bit like
Support multiple JDKs during a single build stepor similar.nipafx commentedon Mar 9, 2021
Since Java 9,
jlinkcan be used to create runtime images that are a subset of the full JDK (and hence OS-specific). For that, the tool needs an unzipped JDK lying around. The cool thing is that it can also create runtime images for a different OS than it is executed on, but then it of course needs that OS's JDK.So it would be nice if setup-java could not only setup (and configure in
toolchains.xml) different Java versions, but also JDKs for different operating systems.bmarwell commentedon Apr 9, 2021
Look what we did for the
maven-jlink-plugin:https://github.com/apache/maven-jlink-plugin/blob/master/.github/workflows/maven.yml
While we could migrate to v2 and still use
AdoptOpenJDK/install-jdk@v1for the secondary java, it would be nice to have this as an out-of-the-box experience.12 remaining items
dsame commentedon Jul 5, 2022
hello @vy, i believe the solution suggested by @jvalkeal do exactly that was requested:
installs all 3 JDKs in their own directory under
/opt/hostedtoolcache/jdk.And in case if it is needed to know the exact location of every JDK just store them somewhere, say in environment :
the result is
and
i think this approach is more straightforward than complicating the action with non-obvious inputs
vy commentedon Jul 6, 2022
Agreed that the concern expressed at the beginning can be addressed by running the action multiple times with different Java versions. As a matter of fact, that is what we ended up doing in Log4j too.
laeubi commentedon Jul 6, 2022
@vy if this is really the solution for this issue, it should mention the snippet on the Help/Readme page, I think this is not that obvious to the usual user.
dsame commentedon Jul 7, 2022
@laeubi thank you for the suggestion, can you please take a look at this PR and confirm it is enough to clarify the use case?
dsame commentedon Jul 15, 2022
The snippet to install multiple JDKs and keep the paths to each in the intermediate variables added to README by the PR #351
Okeanos commentedon Aug 17, 2022
I am currently working on #276 (see #282 as already mentioned by @laeubi), i.e. directly supporting a generation of the
toolchains.xmlfile mentioned in the initial issue comment. The changes are currently being reviewed and do the following things:toolchains.xmlinto the default location, i.e.~/.m2/toolchains.xml, or{{settings-path}}/toolchains.xmlif the input value is specified in thesetup-javastepvendor,version,jdkHome, and (custom or default)idfor the specified JDKtoolchains.xmlin the specified path to add additional JDKs to it without removing existing entriesCheckout the aforementioned issue and PR for more details or in case you want to leave feedback; specifically before the maintainers decide the implementation is integration-worthy.
nielsbasjes commentedon Sep 4, 2022
FYI: I have managed to make this work for my own project like this: https://github.com/nielsbasjes/yauaa/blob/main/.github/workflows/build.yml#L43
dmitry-shibanov commentedon Sep 9, 2022
Hello everyone. We released a new version of setup-java with support of multiple jdks. For now I'm going to close the issue. If you have any concerns feel free to ping us.
Bump JDK running Gradle from 11 to 17
Bump JDK running Gradle from 11 to 17