Can I add custom objects to Velocity context with Maven archetype plugin?

删除回忆录丶 提交于 2019-12-09 16:33:40

问题


We have a number of code generators that use Velocity to generate projects. The generation can be quite complicated:

  • reflection is used (to introspect 3rd party proxies that we have to interface with) prior to calling velocity - the resulting properties (a complex object graph) are added to the velocity context

  • the project structure and files can vary depending on the options selected

  • the templates do more than just variable substitution (they make use of a custom object added to the velocity context, which contains many derived properties, including collections of other objects which are iterated over in the templates)

I'd love to replace these with maven archetypes as they also use Velocity, but it appears they only seem capable of simple variable substitution and a static file/folder structure.

  1. Is there a way to do processing prior to creating a project from an archetype, add objects to the velocity context, and have the archetype templates be able to access them?

  2. If so, can the folders and files to create be dynamic? (or do you need a separate archetype for each variation?)

  3. Or is it better to write a custom Mojo? (essentially wrapping the existing generator with a Maven plugin)

来源:https://stackoverflow.com/questions/12360904/can-i-add-custom-objects-to-velocity-context-with-maven-archetype-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!