今回は、aspect-maven-plugin に定義されている「compile ゴール」で設定できるパラメータを見ていきましょう。 全て紹介するのは面倒なので、独断と偏見で幾つか見繕って説明します(次回以降にも続く。 パラメータ一覧はこちら):
- encoding
- source, target, complianceLevel
- aspectLibraries
- weaveLibraries
- ajdtBuildDefFile
ちなみに、テストコードをコンパイルする「test-compile ゴール」は、「compile ゴール」のパラメータに加えて
- weaveMainSourceFolder
- weaveWithAspectsInMainSourceFolder
を設定することが出来ます。 詳しくはこちら。
encoding
ソースコードの公開のために、ソース・ファイルのエンコーディングを OS のデフォルト・エンコーディングとは違ったエンコーディング形式(例えば UTF-8 など)で保存することがあります。 このとき、コンパイルを正しく行うにはコンパイラにエンコーディング形式の情報を与えなければいけません。 これは、maven-compiler-plugin でソースコードのエンコーディングを指定した方法と同じような方法で行えます:
<project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <!-- ここを追加 --> <configuration> <encoding>UTF-8</encoding> </configuration> ... </plugin> </plugins> </build> </project>
source, target, complianceLevel
「javac」ツールで指定できた -source, -target オプションと同じ指定をするパラメータが、aspectj-maven-plugin でも指定可能です。 これに加えて、予め決められた source, target オプションの組を一括して指定できる「complianceLevel」パラメータも設定可能です:
パラメータ | 説明 | 可能な値 | デフォルト値 |
---|---|---|---|
source | コンパイルするソースコードのバージョン | 1.3, 1.4, 1.5 | 1.4 |
target | 出力するクラスファイルのバージョン | 1.1, 1.2, 1.3, 1.4, 1.5 | 1.2 |
complianceLevel | source, target パラメータの組 | 1.3, 1.4, 1.5 |
ちなみに、complianceLevel の各値で設定される source, target の値は下表の通りです(詳しくはこちら):
complianceLevel | source | target |
---|---|---|
1.3 | 1.3 | 1.1 |
1.4 | 1.4 | 1.2 |
1.5 | 1.5 | 1.5 |
設定方法は、例えば complianceLevel に "1.5" に設定するには
<project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <configuration> <complianceLevel>1.5</complianceLevel> <encoding>UTF-8</encoding> <!-- encoding も同時に設定可 --> </configuration> ... </plugin> </plugins> </build> </project>
とします。