2017-01-14 4 views
2

I Can not mvnパッケージ以下の最小サンプルを使用してください。 Eclipse(Mars.2リリース4.5.2)はコンパイルと織りに問題はありません。Java8向けMaven + AspectJ製織

動作させるには何が必要ですか?

出力:

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
[INFO] Compiling 2 source files to ...\workspace\test\target\classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] .../workspace/test/src/main/java/test/Foo.java:[6,21] cannot find symbol 
    symbol: method doSomethingInjected() 

サンプルクラス:

package test; 

public class Foo { 
    public void bar() { 
     this.doSomethingInjected(); 
    } 
} 

サンプルインターフェース:

package test; 

public interface Injectable { } 

態様:

package test; 

public aspect Injection { 

    declare parents : test..* implements Injectable; 

    public void Injectable.doSomethingInjected() { 
     System.out.println("done"); 
    } 
} 

のpom.xml(aspectj-maven-plugin usage docあたりなどの関連部品)

<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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>test</groupId> 
    <artifactId>test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <dependencies> 
     <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjrt</artifactId> 
      <version>1.8.9</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>aspectj-maven-plugin</artifactId> 
       <version>1.9</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>compile</goal> 
          <goal>test-compile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

答えて

4

それはあなたのプロジェクトがコンパイルして(私はそれをテストした)きれいに実行になり、これを試してみてください:

<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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>de.scrum-master.stackoverflow</groupId> 
    <artifactId>aspectj-introduce-method</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.source-target.version>1.8</java.source-target.version> 
    <aspectj.version>1.8.10</aspectj.version> 
    </properties> 

    <build> 

    <plugins> 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.6.0</version> 
     <configuration> 
      <source>${java.source-target.version}</source> 
      <target>${java.source-target.version}</target> 
      <!-- IMPORTANT --> 
      <useIncrementalCompilation>false</useIncrementalCompilation> 
     </configuration> 
     </plugin> 

     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>aspectj-maven-plugin</artifactId> 
     <version>1.9</version> 
     <configuration> 
      <!--<showWeaveInfo>true</showWeaveInfo>--> 
      <source>${java.source-target.version}</source> 
      <target>${java.source-target.version}</target> 
      <Xlint>ignore</Xlint> 
      <complianceLevel>${java.source-target.version}</complianceLevel> 
      <encoding>${project.build.sourceEncoding}</encoding> 
      <!--<verbose>true</verbose>--> 
      <!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>--> 
     </configuration> 
     <executions> 
      <execution> 
      <!-- IMPORTANT --> 
      <phase>process-sources</phase> 
      <goals> 
       <goal>compile</goal> 
       <goal>test-compile</goal> 
      </goals> 
      </execution> 
     </executions> 
     <dependencies> 
      <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjtools</artifactId> 
      <version>${aspectj.version}</version> 
      </dependency> 
     </dependencies> 
     </plugin> 

    </plugins> 

    </build> 

    <dependencies> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>${aspectj.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    </dependencies> 

</project> 
+0

つの質問:どのように私はそれを構成しますもし私の面がテストジャーに入っているならば、次に、<! - 重要 - >と書かれた2行がなぜ正確に表示されますか?私はなぜそれらが必要であるかについて何らかの説明を見つけることができなかった。 –

+0

質問#2:インクリメンタルコンパイルを使用するにはfalseに設定する必要があるため、これは[bug ticket](https://issues.apache.org/jira/browse/MCOMPILER-209)を参照してください。 Mavenコンパイラ用。 AspectJ Mavenのフェーズを "process-sources"に設定すると、他のコードがMaven Compilerでコンパイルされている場合に問題を回避できます。デフォルトの段階は "コンパイル"されていますが、 "プロセスソース"はほとんどの場合(より早い)です。私はここでコメントに詳しく説明したくありません。 – kriegaex

+0

質問#1:それを使用するモジュールのテスト依存関係としてテストジャーを追加し、それをAspectJ Mavenの 'aspectLibraries'セクションから参照します。おそらく、あなたは 'compile'と' test-compile'のための2つの別個のプラグイン設定/実行を定義して、あなたのテストの面が生産上終わるのを避けるでしょう。しかし、それが必要かどうかは分かりませんが、私は試していません。しかし興味深い質問。さらなるご質問がある場合は、完全に新しい質問を開いて、個別に対処することをお勧めします。 – kriegaex

関連する問題