APT和AOP在同一个项目中,使用Maven
我必须在同一个 Maven 项目中使用注释处理 (apt) 和 AspectJ。
两者都为自己工作,但我需要根据 apt 创建的代码创建方面。所以我需要二进制编织(原始源文件由apt扩展)。如何在 Maven 项目中启用二进制编织?
我知道唯一的标准选项是使用 weaveDependency 提供依赖项 参数,但这很糟糕。还有其他办法吗?
好的,我可以使用 AspectJ ant 任务 嵌入 < a href="http://maven.apache.org/plugins/maven-antrun-plugin/" rel="nofollow noreferrer">Maven Antrun 插件 但我不想诉诸于此。
I have to use Annotation Processing (apt) and AspectJ in the same Maven project.
Both work for themselves, but I need to create aspects based on code created by apt. So I would need binary weaving (the original source files are extended by apt). How can I enable binary weaving within a maven project?
I know the only standard option is to supply a dependency using the weaveDependencies parameter, but this is awful. Is there any other way?
OK, I could embed the AspectJ ant tasks using the Maven Antrun Plugin but I'd hate to resort to that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然我是唯一一个能够回答我自己的问题的人。
我已经通过 ant 使用 Maven Antrun 插件 来编译 AspectJ。这是我的pom片段:
我首先编译java类(并让APT做它的事情),使用编译的类作为aspectj的二进制输入,将aspectj编译到一个新文件夹中并将生成的编织类移动到原始编译目录,覆盖非-aspectj 类。这是我的 ant XML 文件(好的部分是我可以将它用于编译和测试编译):
在下一步中,我现在创建了一个 Maven 插件,它在内部执行所有这些 ant 调用。虽然我无法在这里分享代码,但我将展示它如何简化 POM 配置:
使用 ANT / GMaven 集成,很容易组合 Maven、Groovy 和 Ant 的功能的参数。
I am apparently the only one who can answer my own questions.
I have resorted to compiling AspectJ via ant using the Maven Antrun Plugin. Here's my pom snippet:
I compile java classes first (and let APT do it's stuff), use the compiled classes as binary input for aspectj, compile aspectj into a new folder and move the resulting woven classes to the original compile directory, overwriting the non-aspectj classes. Here's my ant XML file (the nice part is that I can use it for both compile and test-compile):
In the next step I have now created a Maven Plugin that does all this ant calling internally. While I can't share the code here, I'll show how it simplified POM configuration:
Using ANT / GMaven integration, it was easy to assembly the parameters combining the powers of Maven, Groovy and Ant.
受到 Sean Patrick Floyd 上面提出的解决方案的启发,我创建了一个 Maven 插件 开箱即用:
Mojo 目标文档位于 < code>com.jcabi:jcabi-maven-plugin:ajc 使用页面。
Inspired by the solution proposed above by Sean Patrick Floyd I created a Maven plugin that does all that out of the box:
Mojo goal documentation is at
com.jcabi:jcabi-maven-plugin:ajc
usage page.