How to configure Gitpod to start up with JDK-16 (in 2021)

I wished to show some colleagues Gitpod running a git repo which I’m familiar with, to demo what an “ephemeral development environment” looks like in the year 2021

… Except that my chosen repo has a minimum spec of Java 15 16:

“Well this doesn’t sound too hard”, I think…

Except I’ve been banging my head for hours now… Still unsolved issues:

" To do that you need to alter the generated .gitpod.Dockerfile"

I cannot find this generated file. AFAICT, gp init only created 1 file, .gitpod.yml.

I found, for example, this works fine from within the GitPod terminal:

sdk install java 16.0.2.fx-zulu

And javac --version reports JDK 16 as expected.

So I placed that version into a file .gitpod.Dockerfile which I created per the documentation link above. I git-pushed these 2x files and spun up a fresh GitPod instance pointing to my repo. That now spits out some echo 'init script' messages, but it is back on JDK-11.

In a fresh workspace, the simple ./gradlew run command that I hoped to see working does not. Can anyone suggest what I have done wrong?

if it’s working well in the terminal, first try putting a tasks and set the command of that task as sdk install java 16.0.2.fx-zulu as per the .gitpod.yml documentation .gitpod.yml Reference

Thanks. Doing this:

  - init: sdk install java 16.0.2.fx-zulu

prompts with 2 interactive questions. I couldn’t find any sdk flag to disable this :frowning: so I solved it by committing a config file then copying it into place upon init:

  - init: cp /workspace/AdventOfCode/gitpod/sdkman-config /home/gitpod/.sdkman/etc/config &&
       sdk install java 16.0.2.fx-zulu

The time to download these on workspace start is still significant, so I’d like to solve that next.

For my understanding is the “Dockerfile” approach (referenced in the docs about how to configure Java 12) now effectively outdated by the “Prebuild” concept? Or are they complimentary?

Unfortunately no luck with prebuilds. The first workspace launch, which includes performing the prebuild, seems to work and pick up Java 16. On the 2nd and subsequent launch, I’m back to Java 11 (despite some promising sounding messages printed):

Done installing!

Setting java 16.0.2.fx-zulu as default.

🤙 This task ran as a workspace prebuild

gitpod /workspace/AdventOfCode $ java --version

openjdk 11.0.12 2021-07-20 LTS
OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode)

If anyone wants to dive in and take a look:

It may be that the prebuild is not picking up on your changes somehow. Does it work properly if you disable prebuilds?

Yes. It’s worked 2/2 times with:

    master: false
    branches: false

So, based on the fact that your RUN command in the Dockerfile did not work, I would assume that there is something wrong with the Docker building system which is breaking the prebuilds. You should probably open an issue on github.

I don’t understand this bit. After your first suggestion…

if it’s working well in the terminal, first try putting a tasks and set the command of that task as sdk install java 16.0.2.fx-zulu as per the .gitpod.yml documentation

… I stopped using the Dockerfile (I deleted .gitpod.Dockerfile) as I thought we were getting everything set up solely from the .gitpod.yml file. Are you referring to this file, or to some dockerfile created implicitly behind the scenes? (Note that I’m quite ignorant of how Docker works.)

I’m saying I suggested you use just the .gitpod.yml file because it did not seem like the Dockerfile was working, and now I believe that the original problem with the Dockerfile is the same thing that is breaking your prebuilds.

Right, I see. Yes I did get the sense that something racy could be going on - as if something selects JDK-11 again after my changes to JDK-16, during workspace start.