Maven - How to perform conditional execution

谁都会走 提交于 2019-12-01 18:04:01

问题


Is there a way to perform conditional execution of snippet in pom.xml? my requirement is to copy a file/directory to deploy structure based on variable defined in pom.xml...

eg:

< if >
    < equals arg1="package" arg2="package"/>
       < then>
              ....
           < /then>
     < /if>

Not sure how can I achieve this!

Any pointers would be highly appreciated.

Thanks, SR


回答1:


Probably you'll need to use Maven AntRun Plugin for that.

In general, there's no conditional expressions in POM. The only thing similar somehow to this are build profiles that can be activated on some specified conditions, however they probably don't fit into your current case.

And, at the end, my suggestion here. We don't know exactly what your case is about and don't even have any real code snippet, however from my experience it's really unusual to have to use such hackin' stuff in Maven. For me it smells like some problems with Maven understanding, project structure or stuff like that. I may be wrong and maybe your case really needs that, but consider other options to fit into Maven default approach and conventions instead.




回答2:


Well, you can use Maven's profiles, to do that.

Or you can take a look at Maven's Ant Tasks.



来源:https://stackoverflow.com/questions/10993452/maven-how-to-perform-conditional-execution

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