2014-06-13 155 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插件使用該文件。