8

我使用在父pom.xmlSpring 支持中激活

<activation>
    <file>
        <exists>src/main/resources/*beans.xml</exists>
    </file>
</activation>

这工作正常。

当我尝试使用在配置文件中激活 CucumberJVM 内容时

<activation>
    <file>
        <exists>src/test/resources/**/*.feature</exists>
    </file>
</activation>

然而,这拒绝工作。所以我想**通配符在这种情况下被忽略了。

这是否正常,是否有解决方法可以在.feature文件存在时激活此配置文件?

4

2 回答 2

9

我真的很惊讶它的*beans.xml工作原理。

据我所知,文件激活不支持通配符。计算配置文件激活的源代码<file>可以在FileProfileActivator中找到。核心逻辑是这样的:

String path = //<file><exists> ...

RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource(/* ${basedir} suppert */)
interpolator.addValueSource( new MapBasedValueSource( context.getProjectProperties() ) );
interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) );
interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) );
path = interpolator.interpolate( path, "" );
path = pathTranslator.alignToBaseDirectory( path, basedir );
File f = new File( path );
if ( !f.isAbsolute() ){
    return false;
}
boolean isActive = f.exists();

既不interpolate(...)也不alignToBaseDirectory(...)处理通配符。

作为一种解决方法,您可以尝试一些噱头 with <activation><property>,但这需要使用 shell 脚本调用 maven 构建。

于 2013-08-02T10:25:58.830 回答
3

在我们的项目中,我们使用下面的配置使用 jar-plugin 将所有测试打包为 jar 文件:

    <activation>
        <file>
            <exists>src/test/resources/com/companyname/platform/test/</exists>
        </file>
    </activation>

这是能够工作的,因为:

  • 我们使用原型创建样板代码
  • 大多数人只将资源文件放在根文件夹中
  • 配置文件激活适用于目录,至少在 Maven 3.0.5 中
于 2013-10-22T11:33:14.903 回答