Open rafhuys-klarrio opened 15 hours ago
You need to add the sundrio and lombok dependencies to your project: https://github.com/fabric8io/kubernetes-client/blob/main/doc/java-generation-from-CRD.md#quick-start-maven
Here you can find a working example: https://github.com/marcnuri-demo/kubernetes-client/blob/a3ab4ac552b0932324f0ce97387af2a791850611/java-generator/pom.xml
is this possible with the cli as well? or only maven?
the CLI won't generate the builders, it generates source-code that can be processed by the builder generators. Where is the code generated by the CLI consumed? Wherever that code is stored, then the project needs to annotate-process the generated code.
Thank you for the link you sent. But when I run https://github.com/marcnuri-demo/kubernetes-client/blob/master/java-generator/src/test/java/com/hashicorp/secrets/v1beta1/VaultConnectionTest.java I get
/~/kubernetes-client-java-generator/java-generator/src/test/java/com/hashicorp/secrets/v1beta1/VaultConnectionTest.java:50:21
java: cannot find symbol
symbol: class VaultConnectionBuilder
location: class com.hashicorp.secrets.v1beta1.VaultConnectionTest
ok! didn't know about the annotate-process part! Tx
Thank you for the link you sent. But when I run https://github.com/marcnuri-demo/kubernetes-client/blob/master/java-generator/src/test/java/com/hashicorp/secrets/v1beta1/VaultConnectionTest.java I get
/~/kubernetes-client-java-generator/java-generator/src/test/java/com/hashicorp/secrets/v1beta1/VaultConnectionTest.java:50:21 java: cannot find symbol symbol: class VaultConnectionBuilder location: class com.hashicorp.secrets.v1beta1.VaultConnectionTest
Not sure how you're running it, but should simply work by using Maven (mvn verify
)
ok! didn't know about the annotate-process part! Tx
Yes, this is basically the important part. Your builders will be generated as generated-sources
after the annotation processor processes them.
yeah tx for the pointer! Actually I'm writing an SBT plugin for the java-generator. The basic POJO generation is there, but since I don't use Maven ever it's a bit getting used to. So, if I'm following this correctly it's the sundr.io plugin that (should) kick in after the pojo is generated and then creates the Builder class based on the annotation of the base class. I'll have a look if I can manage that to work but this might become a rabbithole rather quickly. Thanks for your help!
So, if I'm following this correctly it's the sundr.io plugin that (should) kick in after the pojo is generated and then creates the Builder class based on the annotation of the base class.
That's correct.
I guess you can run the compilation of the classes to kick in the APT (javac -proc:only
) and then use some other process to move the generated sources elsewhere.
I have a CRD from which I generate the Java Classes. I can add annotations to indicate the Builders of these classes, but is there a way to actually generate the Builder classes as well?
Concretely, I generate the following class based on Traefik Middleware CRD with
./java-gen/java-generator-cli-6.13.4.sh -add-extra-annotations -s traefik.io_middlewares.yaml -t .
Very nice, however there is no constructor for
MiddlewareBuilder
created. How can I generate one?