2014-06-13 150 views
15

我有一个多模块项目。该方面目前被添加到“核心”项目中。在此处执行mvn clean install时可以使用。但是试图在父项目做一个mvn clean install它失败,此错误编译其他项目之一时:编译时使用AspectJ编译器代替Javac时出错

类型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> 

更新

我刚发现。正在运行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> 
+0

什么是异常的堆栈跟踪,你的方面是怎样的? – SpaceTrucker

+0

@KnightRider你应该更新你的问题,而不是添加评论。 –

+0

@LeonardBrünings完成。 –

回答

3

启用行家调用调试进行深入分析。你应该注意到,aspectj编译只在第一次使用clean的maven调用期间被调用。由于builddef.lst在第一次调用后已经存在,因此在不清除的情况下调用将跳过aspectj编译。

这AspectJ的编译插件的行为先前观测并记载:

http://out-println.blogspot.com/2007/08/compile-time-checks-with-aspectj-part-2.html?m=1

您需要更深入,以解决潜在的问题,但作为一个评论者已经提出,AspectJ编译器只应在需要它的模块中启用。

否则,正如您已经观察到的那样,aspectj编译需要额外的依赖关系。我已经将aspectj编译成了我自己的工作,没有问题,仅限于需要它的模块。

3

根据AspectJ compiler Maven plugin,您可以设置argumentFileName以找到现有的builddef.lst

因此,您可以生成builddef.lst并将其复制到资源文件夹,并指示AspectJ Maven插件使用该文件。