-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Initial work on native user API #5610
Conversation
Do you plan on adding a test for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a very nice user experience improvement.
I added a few comments. Only the typo is a must fix, the rest is really to be discussed.
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface RuntimeInitialized { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a silly question and I'm not totally convinced myself but should we stick to the Register
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I did think about it but I think it reads better this way. 'RegisterAsRuntimeInitialized' could be ok as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I wonder if all of these should go in a 'native' package, although it would cause problems with the existing RegisterForReflection.
This guide covers some of the annotations that Quarkus supports to help generate native images. In some cases these | ||
annotations are applied directly to a relevant class, but in others the class that they are placed on does not actually | ||
matter (e.g. if you are referencing a class in a 3rd party jar). In this case we recommend creating an empty `NativeConfig` | ||
class somewhere in your application and placing all annotation that control native image generation on it, so they are all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class somewhere in your application and placing all annotation that control native image generation on it, so they are all | |
class somewhere in your application and placing all annotations that control native image generation on it, so they are all |
annotations are applied directly to a relevant class, but in others the class that they are placed on does not actually | ||
matter (e.g. if you are referencing a class in a 3rd party jar). In this case we recommend creating an empty `NativeConfig` | ||
class somewhere in your application and placing all annotation that control native image generation on it, so they are all | ||
in the same place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a table here summarizing the annotations so that the user has a global overview of what's possible.
} | ||
---- | ||
|
||
In this example only the `ThirdPartyClass` and `ThirdPartyClass` other class are registered, `EmptyClass` is ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that a bit counter intuitive. To be fair the whole annotation approach feels counter intuitive. I wonder if we could allow the class enlistment via an API and annotated toe block of code to be called.
@QuarkusBuild
public void buildOperations(QuarkusBuildOperations ops) {
ops.enlistClassForReflecton(ThirdPartyClass.clas);
ops.otherOperations(...);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grouping those operations into a single interface looks like a nice idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually pretty common in Jakarta EE (annotations that are not directly applicable to the class they are placed on). Some examples:
CDI response producer fields:
@Produces
@EntityManager
EntityManager entityManger;
This enables EntityManager injection in you application, but it can be literally anywhere and the class it is on makes no difference. Same with things like @DataSourceDefinition.
I do agree that it is a bit weird but your solution does not solve the problem of code affecting the whole app that could be anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we would need both, as for the cases where the class is in your application then an annotation is the easiest to understand.
@@ -20,6 +20,14 @@ Please refer to the appropriate section depending on your context. | |||
|
|||
GraalVM imposes a number of constraints and making your application a native executable might require a few tweaks. | |||
|
|||
=== Quarkus Annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mark new features as Preview
in both docs and APIs/Annotations until we are happy we will support them for the while 1.x series.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have decided on the API I don't think there is any issue supporting these, they are just a new facade on functionality we already have.
@@ -278,9 +302,14 @@ method com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode) | |||
Call path from entry point to com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode): | |||
---- | |||
|
|||
If you need to delay the initialization of a class, you can use the `--initialize-at-run-time=<package or class>` configuration knob. | |||
If you need to delay the initialization of a class, you can use the `@io.quarkus.runtime.annotations.RuntimeInitialized` annotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here for API vs annotation.
Also we should explain why a user would want to do that.
|
||
It should be added to the `native-image` configuration using an `<additionalBuildArg>` as shown in the examples above. | ||
Native mode also supports the notion of 'runtime reinitialization' where static init is run at image generation time, and | ||
then re-run at startup. This can be done via the `@io.quarkus.runtime.annotations.RuntimeReinitialized` annotation in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain why you would want to do that. It's dry otherwise.
[source,java] | ||
---- | ||
@RegisterForReflection(targets={ThirdPartyClass.class, OtherClass.class}) | ||
public class EmptyClass { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be NativeConfig
then?
2641c9a
to
b7ce582
Compare
When I looked at the list of subjects, I think while there is value in this extension. It might actually be moot or less important if we really manage to improve #2277 |
@emmanuelbernard do we still want this? If not we should close the PR. |
We want it in some form at some point. Whether I would spend our energy on in in the next 2/3 releases, I don't think so. |
First part of #5601