我在父级激活 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/