【发布时间】:2017-05-11 16:26:11
【问题描述】:
我编写了一个生成源代码的 maven 插件。 这基本上可以正常工作。
问题是,Eclipse 无法将我生成代码的目录识别为附加源文件夹。因此我收到大量错误说XXX cannot be resolved to a type。不过,从命令行编译和安装的 maven 工作正常。
首先我使用org.codehaus.mojo.build-helper-maven-plugin 解决了这个问题。这工作正常。但是,我不喜欢我的插件的用户也需要添加第二个插件。因此,我查看了build-helper-maven-plugin 中的source code of the add-source goal,并决定将相关代码直接添加到我的插件中。因此我的插件看起来像这样:
@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class MyMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
@Parameter(required = true)
private File targetDirectory;
// some more members
@Override
public void execute() throws MojoExecutionException {
// generation of the sources into targetDirectory
project.addCompileSourceRoot(targetDirectory.getAbsolutePath());
}
}
在执行过程中没有错误,无论是从命令行还是从 Eclipse(使用 Alt+F5 或右键单击 -> Maven -> 更新项目)。 但是,无法识别附加的源目录。
我做错了什么吗?还是我需要一个特殊的 m2e 连接器?目前我正在使用 lifecycle-mapping plugin 解决这个 m2e 连接器
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
【问题讨论】:
标签: java m2e maven-mojo