gpt4 book ai didi

maven - 是否可以使用 Maven 属性来激活基于文件的配置文件?

转载 作者:行者123 更新时间:2023-12-04 18:00:38 24 4
gpt4 key购买 nike

当 JACOB dll 不在我的本地存储库中时,我想下载它们。

因此,我有这两个配置文件

    <profile>
<id>use-jacob-dll</id>
<activation>
<file>
<exists>${settings.localRepository}/com/hynnet/jacob/1.18/jacob-1.18-x64.dll</exists>
</file>
</activation>
<dependencies>
<dependency>
<groupId>${jacob.groupId}</groupId>
<artifactId>jacob</artifactId>
<type>dll</type>
<classifier>x64</classifier>
<version>${jacob.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>download-jacob-dll</id>
<activation>
<file>
<missing>${settings.localRepository}/com/hynnet/jacob/1.18/jacob-1.18-x64.dll</missing>
</file>
</activation>

但是,即使 download-jacob-dll 已完成其目标,对 mvn help:active-profiles 的调用也会指示以下内容

The following profiles are active:

- tests-for-eclipse (source: com.capgemini.admdt:kpitv:1.2.4-SNAPSHOT)
- download-jacob-dll (source: com.capgemini.admdt:kpitv:1.2.4-SNAPSHOT)

我怀疑这是因为我在激活属性中使用了 ${settings.localRepository}

问题:是失败的原因吗?如果是这样,我如何才能仅在缺少依赖项时激活我的配置文件?

最佳答案

Is it possible to use a maven property to activate a profile based upon a file?

不,如 Maven documentation on profiles 所述

Supported variables are system properties like ${user.home} and environment variables like ${env.HOME}. Please note that properties and values defined in the POM itself are not available for interpolation here, e.g. the above example activator cannot use ${project.build.directory} but needs to hard-code the path target.

但是,从 POM documentation我们也明白了

a given filename may activate the profile by the existence of a file, or if it is missing. NOTE: interpolation for this element is limited to ${basedir}, System properties and request properties.

因此,确实没有 Maven 属性 except ${basedir} 是允许的。


And if so, how can I activate my profile only when dependency is missing?

通过硬编码到依赖项或相关文件的路径将是一个解决方案,即使不像您所指的解决方案那样可移植。

或者,您可以使用上面文档中提到的 request 属性,因此需要使用一个必须从命令行传递的属性来配置激活(更便携但也更脆弱) ):

<activation>
<file>
<missing>${path}/com/hynnet/jacob/1.18/jacob-1.18-x64.dll</missing>
</file>
</activation>

然后调用maven如下:

mvn clean install -Dpath=path_to_local_rep

上述解决方案在某些情况下可能是合理的,例如 Jenkins 作业。

关于maven - 是否可以使用 Maven 属性来激活基于文件的配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35943162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com