有什么办法可以去掉maven的一些注释吗?
我想知道是否有办法在 'maven build' 时去掉一些注释?
为了方便起见,我将一些第三方的注释添加到我的 POJO 中,例如 javax.persistence.* 、 org.hibernate.annotations.* 、 org.apache .lucene.analysis.* ...废话...废话。
当我将它们捆绑在一起并部署到 JavaEE/Spring 服务器/容器时,效果很好。
但是在开发 Android 时,我希望最大限度地重用我的代码/POJO。我想直接导入 foobar.core.User 而不是创建另一个没有第三方注释的 foobar.android.User 。也就是说,我不希望 jar 依赖于其他 spring/hibernate 工件。
那么,有什么方法可以在运行“maven build”时去掉一些注释吗?我只需要去掉“一些”第三方注释,并保留自定义核心注释。
这样我就可以分别或同时构建foobar-core.jar
和foobar-core-stripped.jar
。
I wonder if there a way to strip off some annotations when 'maven build' ?
For convenience reason , I annotate some 3rd party's annotation into my POJO , such as javax.persistence.*
, org.hibernate.annotations.*
, org.apache.lucene.analysis.*
... blah...blah.
It works well when I bundle them together and deploy to a JavaEE/Spring server/container.
But when developing Android , I want to make the most reuse of my code/POJOs. I want to directly import foobar.core.User instead of creating another foobar.android.User without 3rd party annotations. That is , I don't want the jar dependent on other spring/hibernate artifacts.
So , is there any way to strip off some annotations when running 'maven build' ? I just need to strip off 'some' 3rd party annotations , and keep custom core annotations.
So that I can build foobar-core.jar
and foobar-core-stripped.jar
respectively or simultaneously.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试做完全相同的事情。我发现一个 ant 任务可以从编译的类中删除注释。
http://sourceforge.net/projects/purgeannorefs/
然后可以使用maven ant插件来调用ant 任务作为 Maven 构建的一部分。
我知道这是一个解决方法。但比必须维护 2 个 pojo 对象的副本要好。
Trying to do exactly the same thing. I found an ant task that can strip annotations from compiled classes.
http://sourceforge.net/projects/purgeannorefs/
The maven ant plugin can then be used to call the ant task as part of your maven build.
I know it's a bit of a workaround. But better than having to maintain 2 copies of the pojo objects.
如果你找不到可以完成这项工作的非 Maven 工具,那么你就找不到 Maven 插件。 Mmake 注释类的存根副本将它们放入 jar 中,并将它们添加到 Android 的类路径中。
If you can't find a non-maven tool that does the job, you aren't going to find a maven plugin. Mmake stub copies of the annotation classes put them in a jar, and add them into the classpath for Android.
您可以使用 maven-antrun-plugin 对所有注释进行查找和替换...我在以下答案中执行此操作以注释掉所有 @XmlAttribute 注释:
https://stackoverflow.com/a/10036841/342745
有点hacky,但它对我有用。
You can use the maven-antrun-plugin to do a find and replace on all annotations... I did this at the following answer to comment out all @XmlAttribute annotations:
https://stackoverflow.com/a/10036841/342745
Kind of hacky, but it worked for me.