maven - 当文件存在时使用通配符激活配置文件

标签 maven cucumber activation profiles

我在父级激活 pom.xml Spring 支持使用

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

这工作正常。

当我尝试使用以下方法激活配置文件中的 CucumberJVM 内容时
<activation>
    <file>
        <exists>src/test/resources/**/*.feature</exists>
    </file>
</activation>

然而,这拒绝工作。所以我猜 **在此上下文中将忽略通配符。

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

最佳答案

我真的很惊讶 *beans.xml作品。

据我所知,不支持通配符 在文件激活中。基于<file>计算profile激活的源码可以在 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(...)处理通配符。

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

关于maven - 当文件存在时使用通配符激活配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674116/

相关文章:

ruby-on-rails - Cucumber: stub 、模拟或记录客户调用(谷歌地图)

java - 使用文件存在忽略我的 Maven 配置文件中的激活(配置文件始终执行)

java - 为什么这个maven错误突然

java - 如何使用 maven/travis 将二进制文件打包、压缩并部署为 zip/tar.gz 从 github 存储库到 bintray.com 通用存储库

cucumber - 如何将示例表添加到 cucumber 特征文件的背景中?

makefile - 如何使用makefile激活virtualenv?

使用 django.contrib.messages 重定向 Django 注册激活

java - Maven 程序集的替代方案 :single for packaging

java - Smooks - 无法执行目标 org.codehaus.mojo :exec-maven-plugin:1. 2.1:exec

ruby-on-rails - Cucumber/Capybara -- 如何获取当前执行的主机和端口