Maven 2系からMaven 3系に移行した際に、Mojoで意図したcompileClasspathElementsやtestClasspathElementsが取得出来ない場合の解決方法
Maven 2系から3系への乗り換えで一部Mojoが正常に動かずに超絶ハマったのでメモ。
発生する問題
Maven 2系列の場合、例えば compile フェーズであれば (特に指定していなければ)compileClasspathElements で以下のような値(正確にはList
[module]\target\classes, [関連するjar]
しかしながら、Maven 3系列では以下のような値しか取れません。
[module]\target\classes
解決策
MojoのJavadocにrequiresDependencyResolutionアノテーションを指定する。
最新のMojo api specificationのThe Descriptor and Annotationsを見てみると、requiresDependencyResolutionアノテーションの説明が昔に比べて増えた事がわかります。
(参考までに、2009年6月28日時点での説明)
説明を見てみると
If the annotation is not present at all, the mojo must not make any assumptions about the artifacts associated with a Maven project.
なんて書いてあります。
アーティファクトに関係するものまでclasspathに含めたければ、指定しないといけなくなったっぽいですね。