プラグインはgenerate-sources
段階的に実行する必要があります。次に、生成されたソースが通常のcompile
フェーズで使用可能であることを確認する必要があります。
プラグインは次のように構成する必要があります。
<build>
<plugins>
<plugin>
<groupId>your.group</groupId>
<artifactId>your-generator-plugin</artifactId>
<version>your-generator-version</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>your-generator-goal</goal>
</goals>
<configuration>
<!-- Here goes all the plugin configuration -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
プラグイン (mojo) から直接、使用するコンパイル ソース パスを追加できます。
モジョに追加する必要があるものの例を次に示します。
/**
* The current project representation.
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* Directory wherein generated source will be put; main, test, site, ... will be added implictly.
* @parameter expression="${outputDir}" default-value="${project.build.directory}/src-generated"
* @required
*/
private File outputDir;
そして、このようなものをメソッドに追加する必要がありますexecute()
:
if (!settings.isInteractiveMode()) {
LOG.info("Adding " + outputDir.getAbsolutePath() + " to compile source root");
}
project.addCompileSourceRoot(outputDir.getAbsolutePath());
これにより、生成されたJavaソースファイルが出力されtarget/src-generated/
ますが、mojoで他のデフォルト値に変更するか、これをプラグインの構成部分に追加することで変更できます:
<outputDir>path/to/my/generated/source/</outputDir>
compile
生成された Java ソース ファイルは、フェーズに自動的に含まれます。