how to generate and use java files in generated sources properly
i have this code snipped
that creates a version enum at the mentioned path. however my main project doesnt seem to find it (and neither does the github action i have setup)
8 Replies
⌛
This post has been reserved for your question.
Hey @Asdru! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
You shouldn't do it this way.
Once your application is packaged in a JAR or similar, there will be no generated-sources or target folder
these folders only exist while you are developing the application
if you want to generate code at compile-time, take a look at annotation processors
and if you need to generate code at runtime, you could in principle use class loading to generate it but then you couldn't call it without reflection
Also note this other problem with your current approach: If you just write files to generated sources, you would need to recompile your application) (which may delete the generated sources directory) to use these classes
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Oh ok thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
It takes a while to run since its fetching data from the web, thats why i separated it into its own main function
There are two situations where you are allowed to modify the contents of the generated-sources folder:
- in an annotation processor
- in certain phases during the Maven build
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.