我正在使用Maven 3.5+,我已经读到Maven 3.2.2+支持激活配置文件的条件。所以我在配置文件的激活标签中添加了多个条件,如下所示:
<activation>
<file>
<exists>${basedir}/src/main/resources/static/index.html</exists>
<missing>${basedir}/src/main/resources/static/app/gen-src/metadata.json</missing>
</file>
</activation>
我把它放在父项目的pom.xml.中,当子项目包含索引时,配置文件应该执行.html但没有metadata.json。 当我编译同时具有 index.html 和 metadata.json 的子项目时,配置文件已激活,插件将执行。但在这种情况下,配置文件不应处于活动状态。我认为条件或由专家。
查看 v3.5.0ActivationFile
javadoc(尚找不到源代码(和FileProfileActivator
源代码,目前似乎无法处理多个文件,并且存在此问题。
文件激活配置接受 2 个参数,一个用于现有文件,一个用于丢失文件。因此,这两个参数都会影响相同的配置,并且您只能有一个这样的配置。
因此,如果两个值都设置了,它将按此顺序查找现有文件或丢失的文件,但不查找这两个值。不幸的是,到目前为止我找不到解决方法...
1(ActivationFile
javadoc:
公共类激活文件
扩展对象
实现可序列化、可克隆、输入位置跟踪器这是用于激活配置文件的文件规范。缺失值是需要存在的文件的位置,如果没有,配置文件将被激活。另一方面,存在将测试文件是否存在,如果存在,配置文件将被激活。 这些文件规范的变量插值仅限于 ${basedir}、系统属性和请求属性。
2(FileProfileActivator
来源(请注意,为了简洁起见,我省略了一些插值代码(
@Override
public boolean isActive(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
Activation activation = profile.getActivation();
if (activation == null) {
return false;
}
ActivationFile file = activation.getFile();
if (file == null) {
return false;
}
String path;
boolean missing;
if (StringUtils.isNotEmpty(file.getExists())) {
path = file.getExists();
missing = false;
} else if (StringUtils.isNotEmpty(file.getMissing())) {
path = file.getMissing();
missing = true;
} else {
return false;
}
/* ===> interpolation code omitted for the sake of brevity <=== */
// replace activation value with interpolated value
if (missing) {
file.setMissing(path);
} else {
file.setExists(path);
}
File f = new File(path);
if (!f.isAbsolute()) {
return false;
}
boolean fileExists = f.exists();
return missing ? !fileExists : fileExists;
}