Closed ChrisBrenton closed 7 years ago
Without a proper example, it's a little hard for me to tell, but if you are making modifications to the generated classes under build
, then of course, it gets cleaned up on a new build. If you want to use your own version of a generated class, simply provide your version under the same java package as where it would be generated. See Issue #13 and Issue #16 for the solution and examples.
Note that you would also benefit from having your modifications version-controlled.
Let me know if that answers your question.
Thank you for your prompt response.
In the first instance, the jjtree file is in src/main/javacc (which is the compileJjtree and compileJavacc tasks' input and output directory) with no other files so naturally they are generated the first time. Once they are generated, however, classes with the exact name already exist for the second build, so shouldn't be re-generated?
build.gradle: https://gist.github.com/ChrisBrenton/42e78537464262ee73a4b3083d0f3a60
I don't understand why you override the inputDirectory and outputDirectory properties. I think the behaviour you are looking for is broken by you having both the input and ouput in the same directory. The default behaviour will do the right thing in using the output of JJTree as the input for JavaCC. If you have Java classes in the JavaCC input directory, it will not regenerate these classes in the output directory.
So, bottom line, I suggest you leave out the input/output configuration, do a one-off generation of your classes, move the ones you need to modify so src/main/javacc, make the modifications and add that to version control. Then, next time you regenerate, these classes won't be generated and your custom AST class will be used.
It's usually bad practice to generate stuff in source folders, hence why the default behaviour does not go this way. You don't need to worry about where the generated classes are, they will still be packaged correctly.
Closing this issue.
I may be missing something here, so please correct me.
JavaCC (through standard terminal usage) allows you to modify auto-generated AST classes, and when recompiling it will not automatically recreate them removing all modifications. I cannot get the same behaviour using this plug-in.
Am I missing something?