如何:让Lombok和AspectJ一起工作
如何:Maven,Lombok和AspectJ一起
如果您在此页面上,则有自己的用途,您想要配置maven pom.xml以同时启用lombok和Aspectj的用法。解决方案是禁止Aspectj-Maven-plugin重新生成类文件,因为在没有任何配置的情况下,编译和编织过程看起来是这样的:
- javac使用lombok将您的.java文件编译为.class文件(生成对应的方法getter,setter等)
- Aspectj无需lombok即可从.java文件重新生成类
因此,我们需要使用aspectj插件的就地编织功能:
1个 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18岁 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | … < build > … < plugins > … < plugin > < groupId >org.codehaus.mojo</ groupId > < artifactId >aspectj-maven-plugin</ artifactId > < version >1.4</ version > < dependencies > < dependency > < groupId >org.aspectj</ groupId > < artifactId >aspectjrt</ artifactId > < version >1.6.12</ version > </ dependency > < dependency > < groupId >org.aspectj</ groupId > < artifactId >aspectjtools</ artifactId > < version >1.6.12</ version > </ dependency > </ dependencies > < executions > < execution > < phase >process-classes</ phase > < goals > < goal >compile</ goal > </ goals > </ execution > </ executions > < configuration > < showWeaveInfo /> < forceAjcCompile >true</ forceAjcCompile > < sources /> < weaveDirectories > < weaveDirectory >${project.build.directory}/classes</ weaveDirectory > </ weaveDirectories > < aspectLibraries > … </ aspectLibraries > < source >1.6</ source > < target >1.6</ target > </ configuration > </ plugin > … </ plugins > … </ build > … |
解决方案的关键是配置中的空源标签和forceAjcCompile = true设置。
还没有评论,来说两句吧...