Skip to content
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

Generated classes are not available with nativeTest #32428

Closed
snicoll opened this issue Sep 20, 2022 · 1 comment
Closed

Generated classes are not available with nativeTest #32428

snicoll opened this issue Sep 20, 2022 · 1 comment
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Sep 20, 2022

This can be reproduced using https://github.com/snicoll/demo-aot-native

A call to ./gradlew nativeCompile works as expected.

However, calling ./gradlew nativeTest leads to:

> Task :nativeTestCompile
[native-image-plugin] Toolchain detection is disabled, will use GraalVM from /Users/snicoll/.sdkman/candidates/java/graalvm.
[native-image-plugin] Using executable path: /Users/snicoll/.sdkman/candidates/java/graalvm/bin/native-image
========================================================================================================================
GraalVM Native Image: Generating 'demo-aot-native-tests' (executable)...
========================================================================================================================
Warning: Could not resolve com.example.demo.DemoAotNativeApplication$$SpringCGLIB$$0 for reflection configuration. Reason: java.lang.ClassNotFoundException: com.example.demo.DemoAotNativeApplication$$SpringCGLIB$$0.

The com.example.demo.DemoAotNativeApplication$$SpringCGLIB$$0 class is generated in the expected directory:

$ tree build/generated/aotTestClasses
build/generated/aotTestClasses
└── com
    └── example
        └── demo
            └── DemoAotNativeApplication$$SpringCGLIB$$0.class

3 directories, 1 file
@snicoll snicoll added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Sep 20, 2022
@snicoll snicoll added this to the 3.0.0-M5 milestone Sep 20, 2022
@wilkinsona wilkinsona self-assigned this Sep 20, 2022
@wilkinsona
Copy link
Member

wilkinsona commented Sep 20, 2022

It isn't the cause of this problem, but why is generation of test classes processing main code? If you run processAot and processAotTest, you'll see that DemoAotNativeApplication$$SpringCGLIB$$0.class has been generated twice:

build/generated
├── aotClasses
│   └── com
│       └── example
│           └── demo
│               └── DemoAotNativeApplication$$SpringCGLIB$$0.class
…
├── aotTestClasses
│   └── com
│       └── example
│           └── demo
│               └── DemoAotNativeApplication$$SpringCGLIB$$0.class

This appears to be specific to class generation as I don't see the same duplication in the generated sources. The two classes are identical, but having two copies doesn't feel right. For tests, I think we should use the one from aotClasses as it's the one that should be used at runtime. The ideal would be for only one to be generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants