Skip to content

Capturing env var during build time no longer works. #7981

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

Closed
borkdude opened this issue Dec 7, 2023 · 2 comments
Closed

Capturing env var during build time no longer works. #7981

borkdude opened this issue Dec 7, 2023 · 2 comments

Comments

@borkdude
Copy link

borkdude commented Dec 7, 2023

Repro:

public class Env {
    public static String FOO = System.getenv("FOO");
    public static void main(String [] args) {
        System.out.println("FOO at build time: " + FOO);
    }
}

Compile with CE 22.3.1 and run FOO=1 $GRAALVM_HOME/bin/native-image --initialize-at-build-time=Env Env
Running the binary ./env produces:

$ ./env
FOO at build time: 1

However with Oracle GraalVM 21:

$ ./env
FOO at build time: null
@zakkak
Copy link
Collaborator

zakkak commented Dec 7, 2023

Hi @borkdude, starting with GraalVM 23.0.0 you need to explicitly define which env variables should get embedded in the native image using the -E option.

The following will do the trick in your example:

$ FOO=1 native-image --initialize-at-build-time=Env Env -EFOO
...
$ ./env
FOO at build time: 1

@zakkak zakkak closed this as completed Dec 7, 2023
@borkdude
Copy link
Author

borkdude commented Dec 8, 2023

@zakkak Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants