java mojo是什么_java – 动态地将mojo生成的代码添加到源路径

我创作了一个生成代码并将其粘贴在{root} / target / generated-sources / foo下的mojo.当我执行:

mvn clean install

我收到错误,表明生成的源没有包含在构建路径中(生成的文件在那里,但在编译阶段没有被选中).我从this answer了解到我需要动态添加{root} / target / generated-sources / foo作为POM的源目录.问题是,我无法找到有关如何执行此操作的任何信息.

作为备份计划,我打算使用Build Helper Maven插件,但我希望尽可能在我的mojo中自动执行此操作.

最佳答案 我更喜欢将它添加到我的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());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值