【问题标题】:Maven profile file activation failsMaven 配置文件激活失败
【发布时间】:2018-02-08 10:16:28
【问题描述】:

我有一个父 pom,它定义了当定义的文件夹存在时应激活的配置文件:

<groupId>common</groupId>
<artifactId>common-build</artifactId>

<profiles>
    <profile>
        <id>dependency-profile-ejb</id>
        <activation>
            <file>
                <exists>${basedir}/src/profile/dependency-ejb/</exists>
            </file>
        </activation>
        <dependencies>[...]</dependencies>
    </profile>
    <profile>
        <id>dependency-profile-jsf</id>
        <activation>
            <file>
                <exists>${basedir}/src/profile/dependency-jsf/</exists>
            </file>
        </activation>
        <dependencies>[...]</dependencies>
    </profile>
</profiles>

我有一个包含几个子模块的 maven 项目:

<parent>
    <groupId>common</groupId>
    <artifactId>common-build</artifactId>
</parent>

<groupId>project/groupId>
<artifactId>project-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>

<modules>
    <module>project-child-one<module>
</modules>

在子项目中我只是定义了父依赖:

<parent>
    <groupId>project</groupId>
    <artifactId>project-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>project-child-one</artifactId>

在这个子项目中,我定义了文件夹src/profile/dependency-ejb

如果我在 Eclipse 中运行项目的构建,一切都会按预期工作。然后我在 jenkins 中安装了该项目,但构建失败。如果我将project-parent 检出到一个干净的目录并尝试运行一个 Maven 构建,构建也会失败。

为什么构建在 Eclipse 中运行而不是在命令行中运行?为什么 common-build 的父 pom 中的配置文件定义不被尊重?

【问题讨论】:

  • 你好,你能用${project.basedir}代替${basedir}吗?
  • 运行mvn -X ... 可能会在这种情况下提供洞察力。

标签: maven maven-profiles


【解决方案1】:

经过进一步的测试,我找到了解决方案。构建失败,因为配置文件激活的文件夹丢失。我已将项目添加到 git 并忘记了 git 不会提交/推送空文件夹。

解决方案是在文件夹中添加一个空的.gitkeep 以强制 git 提交/推送它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-12
    • 2014-10-29
    • 2018-07-03
    • 2015-03-30
    • 1970-01-01
    • 2019-05-17
    • 2010-12-03
    • 2011-06-05
    相关资源
    最近更新 更多