Kni*_*der 15 java hibernate aspectj java-ee maven
我有一个多模块项目.该方面目前已添加到"核心"项目中.在mvn clean install这里做它有效.但是,mvn clean install在编译父项目时,在编译其他项目时,它会因此错误而失败:
无法解析org.hibernate.annotations.CacheConcurrencyStrategy类型.它是从所需的.class文件间接引用的
如果我在该项目中添加Hibernate核心依赖项也可以,但是将依赖项添加到不应该具有依赖项的项目中是没有意义的 - 所以它不是一个解决方案.用javac它编译时工作正常.
是什么原因?我如何解决它,以便我可以使用AspectJ编译器而不会泄漏依赖项到不应该有的项目?
我在父POM中有这个配置:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<complianceLevel>1.6</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
更新
我刚刚发现.mvn clean install每次都运行失败.但是,运行mvn [clean] install一次失败.然后mvn install没有clean工作运行.我看到builddef.lst目标文件夹中的原因是它运行的原因并根据您是否运行干净而失败.所以现在我的问题是:你如何自动生成这个文件?
父POM文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>core-lib</artifactId>
<name>core-lib</name>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<complianceLevel>1.6</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
</dependencies>
<modules>
<module>core-xyz</module>
<module>core-xyz2</module>
</modules>
</project>
Run Code Online (Sandbox Code Playgroud)
小智 3
在 Maven 调用上启用调试以进行更深入的挖掘。您应该观察到,aspectj 编译仅在第一次使用 clean 调用 Maven 期间被调用。由于第一次调用后 builddef.lst 已经存在,因此在不使用 clean 的情况下调用会跳过aspectj 编译。
之前已经观察到了这个aspectj编译插件行为,并在此处进行了描述:
http://out-println.blogspot.com/2007/08/compile-time-checks-with-aspectj-part-2.html?m=1
您需要更深入地研究才能解决根本问题,但正如一位评论者已经建议的那样,aspectj 编译器应该只在需要它的模块中启用。
否则,正如您已经观察到的,aspectj 编译需要额外的依赖项。我已将aspectj编译合并到我自己的工作中,通过将其限制为仅需要它的模块,没有出现任何问题。