2017-11-14 19 views
1

나는 광범위하게 검색하여 내 문제를 해결하는 데 도움이되는 것을 찾지 못했습니다. 나는 특정 기능을 구현하기 위해 노력하고 내가 의한 PoC 솔루션을 생성하고, 여기에 비록 문제 :한 프로젝트에서 Aspectj 컴파일 시간 짜기 및 Java 컴파일 타임 주석 처리 사용

은 컴파일 시간을 모두 사용하는 것은 AspectJ를을 직조 및 시간 주석 프로세서를

를 컴파일하고 난 몰라 그 두 가지 작업을 동시에 수행하는 방법.

지금까지 aspectj-maven-plugin을 사용하여 * .aj 파일에서 AspectJ aspect만을 사용하고 있었고 정상적으로 작동하고있었습니다. maven-compiler-plugin을 사용하여 주석 처리를 추가하자마자 문제가 발생했습니다 : aspectj-maven-plugin에 의해 컴파일 단계에서 생성 된 대상 디렉토리의 weaved 클래스가 maven-compiler-plugin에 의해 덮어 쓰여졌습니다 그것은 컴파일 단계에서 생성 된 클래스에 의해 수행됩니다.

[INFO] --- aspectj-maven-plugin:1.10:compile (default) @ demo --- 
[INFO] Showing AJC message detail for messages of types: [error, warning, fail] 
...and a list of all the Join Points and Intertypes done 

그러나 받는다는 - 컴파일러 플러그인이 일을하러 모든 것을 다시 컴파일 (와 클래스를 생성

콘솔 출력은 먼저 AspectJ를-받는다는 - 플러그인은이 작업의 수행과 모든 클래스를 엮어 말한다 주석 처리기)로 :

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
</plugin> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<version>3.7.0</version> 
<configuration> 
    <source>${maven.compiler.source}</source> 
    <target>${maven.compiler.target}</target> 
</configuration> 
<executions> 
    <execution> 
     <id>default-compile</id> 
     <configuration> 
      <compilerArgument>-proc:none</compilerArgument> 
      <includes> 
       <include> 
        path/to/annotation/processor/Processor.java 
       </include> 
      </includes> 
     </configuration> 
    </execution> 
    <execution> 
     <id>compile-project</id> 
     <phase>compile</phase> 
     <goals> 
      <goal>compile</goal> 
     </goals> 
    </execution> 
</executions> 
</plugin> 
<plugin> 
<groupId>org.codehaus.mojo</groupId> 
<artifactId>aspectj-maven-plugin</artifactId> 
<version>1.10</version> 
<dependencies> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjtools</artifactId> 
     <version>${aspectj.version}</version> 
    </dependency> 
</dependencies> 
<configuration> 
    <showWeaveInfo>true</showWeaveInfo> 
    <complianceLevel>${maven.compiler.source}</complianceLevel> 
    <source>${maven.compiler.source}</source> 
    <target>${maven.compiler.target}</target> 
</configuration> 
<executions>   
    <execution> 
     <phase>process-sources</phase> 
     <goals> 
      <goal>compile</goal> 
      <goal>test-compile</goal> 
     </goals> 
    </execution> 
</executions> 
</plugin> 
: 여기
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ demo --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 1 source file to dir\demo\target\classes 
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (compile-project) @ demo --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 19 source files to dir\demo\target\classes 

는 pom.xml 파일의 관련 부분은

별도로 aspect와 annotation processor가 모두 잘 작동하므로 특별히 문제가되지 않습니다. 문제는 빌드 구성이라고 가정합니다.

나는 플러그인에서 실행/단계로 뭔가를 망쳐 놓고있는 것 같아요, 아니면 둘 다 사용하지 않아도 될 것입니다. 어쩌면 하나만으로 충분할 수도 있지만, 컴파일을 ajc와 결합하고 주석 처리기를 실행하는 방법에 대해서는 전혀 알지 못합니다. (그리고 주석 처리기 자체를 컴파일하고 주석 처리를 수행하는 데는 proc 없음을 먼저 사용합니다. 도와주세요!

답변

0

필자에게 가장 좋은 전략은 AspectJ 컴파일러를 사용할 때 Java 컴파일러를 모두 비활성화하고 AspectJ 컴파일러에서 주석 처리 및 컴파일 만 수행하는 것이 었습니다. 예를 받는다는 빌드 구성은 다음과 같이 보일 것이다 :

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <skipMain>true</skipMain> 
       <skip>true</skip> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>aspectj-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

을 그 어떤 이유로 당신을 위해 작동하지 않는 경우에, 당신은 주석 처리만을위한 자바 컴파일러를 사용하여 시도하고 AspectJ의 컴파일러가 나머지를 할 수 있습니다.

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <proc>only</proc> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>aspectj-maven-plugin</artifactId> 
      <configuration> 
       <proc>none</proc> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

는 또한 당신이 당신의 빌드 파일에 정의 너무 많은 실행에있어 참조 : 기본이 아닌 실행 ID로 (자바 컴파일러 2 default-compile + compile-project). 특별한 이유가없는 한 기본 실행 만 기본 ID로 남겨 두는 것이 좋습니다.