我更喜欢将其添加到我的 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;
显然,您可以更改default-value
以匹配您自己的模式。
然后在execute()
方法中:
if (!settings.isInteractiveMode()) {
LOG.info("Adding " + outputDir.getAbsolutePath() + " to compile source root");
}
project.addCompileSourceRoot(outputDir.getAbsolutePath());