使用Maven插件测试工具测试Mojos的默认值和表达式: [英] Test default values and expressions of Mojos using Maven Plugin Testing Harness:

查看:72
本文介绍了使用Maven插件测试工具测试Mojos的默认值和表达式:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Maven插件测试工具(2.0-alpha1)时遇到问题:当我要测试Mojo时,默认值和参数表达式不适用. 我有以下参数:

I have a problem using the Maven Plugin Testing Harness (2.0-alpha1): When I want to test my Mojo, the default values and expressions for parameters are not applicable. I have the following parameter:

/**
 * <p>The output file to write the settings to.</p>
 *
 * @parameter default-value="${project.build.directory}/myProperties.properties" expression="${properties.file}"
 */

private String file;

当我运行单元测试时,此属性始终为null.我试图注入一个MavenProjectStub,它成功返回${project.build.directory},但是这不适用于我的Mojo参数.

When I run my unit tests this property is always null. I tried to inject a MavenProjectStub which returns ${project.build.directory} successfully but this is not applied to my Mojo parameter.

在测试期间,是否可以在Mojos中启用默认值和表达式,例如${project.build.directory}?

Is there any way to enable default values and expressions like ${project.build.directory} inside my Mojos during the tests?

推荐答案

所以它看起来像它们已添加lookupConfiguredMojo仅用于此用例.我花了一些时间弄清楚如何调用它,因为您需要正确配置的MavenProject才能使用它.这是对我有用的东西:

So it looks like they added lookupConfiguredMojo for just this use case. It took me a while to figure out how to call that because you need a properly configured MavenProject to use it. Here's what worked for me:

File pomFile = ...

MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();

MyMojo mojo = (MyMojo) this.lookupConfiguredMojo(project, "my-goal");
...

这篇关于使用Maven插件测试工具测试Mojos的默认值和表达式:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆