What is a good strategy for dealing with generated code? One of our projects uses Apache CXF’s wsdl2java tool to generate JAX-WS stubs for a set of wsdls. How should this code be dealt with?
There are two options that I can see:
-
Generate the stubs once and store them in version control. With this, you don’t have to deal with IDE classpath issues since you have the source files right there in your tree (or nearby). However, you have a lot of extra clutter in version control in addition to the temptation for someone to monkey with the generated code
-
The stubs are generated every time at build time. This reverses the pros/cons for #1 in that the developer now has to deal run the build script and add the resulting jars to his/her classpath.
We went with #2 because the annoyance of classpath related issues seemed to outweigh the problems detailed in #1.
What are other people doing? Does anyone have any recommendations to streamline this process?
My attitude is that generated code should practically never be stored in version control. There has to be a compelling reason to do it. I typically create an ant task ‘build-for-eclipse’ that builds all generated code. I run that, refresh the directory into which generated code is created, and voilà, I am fit to go.
The goal is that you have a ‘one-button’ trivial task that any developer can do so they’ll have all the source — generated and not — in their IDE, but that no output of anything is stored in source control. If it’s the output of a generator, then by definition it’s not source. 🙂
This should safely meet everyone’s needs.