【问题标题】:Maven: Only want to run profile if doing a build on the parent pomMaven:如果在父 pom 上进行构建,则只想运行配置文件
【发布时间】:2011-09-12 15:38:21
【问题描述】:

我正在使用 Maven 3.0.3。我有一个从父级继承的项目……

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myco.util.ant</groupId>
    <artifactId>selenium-framework</artifactId>
    <packaging>jar</packaging>
    <name>Myco Selenium Utils</name>
    <parent>
            <groupId>com.nna</groupId>
            <artifactId>parent</artifactId>
            <version>1.2-SNAPSHOT</version>
            <relativePath>../parent</relativePath>
    </parent>

在我的父母 pom 中,我有以下个人资料。但是,我只希望这个配置文件在有人在父 pom 上进行构建时才处于活动状态,而不是在它的一个孩子上。有谁知道我可以如何调整以下内容,以便在有人构建子项目时不会激活它?

            <profile>
                    <id>deploy-snapshot</id>
                    <build>
                            <plugins>
                                    <plugin>
                                            <artifactId>maven-antrun-plugin</artifactId>
                                            <version>1.6</version>
                                            <executions>
                                                    <execution>
                                                            <phase>deploy</phase>
                                                            <configuration>
                                                                    <target>
                                                                            <condition property="is-release">
                                                                                    <not>
                                                                                            <contains string="${project.version}" substring="SNAPSHOT" />
                                                                                    </not>
                                                                            </condition>
                                                                            <fail if="is-release" message="You can only deploy snapshot versions of this project." />
                                                                    </target>
                                                            </configuration>
                                                            <goals>
                                                                    <goal>run</goal>
                                                            </goals>
                                                    </execution>
                                            </executions>
                                    </plugin>
                            </plugins>
                    </build>
                    <activation>
                            <activeByDefault>true</activeByDefault>
                    </activation>
            </profile>

谢谢, - 戴夫

【问题讨论】:

    标签: maven-2 maven


    【解决方案1】:

    您可以尝试通过文件或目录的存在/不存在来激活它。您可以找到example in the Sonatype Maven book。请注意,“当前工作目录”和“${project.basedir}”之间存在差异,如果这对您很重要的话,Maven 2 和 Maven 3 之间的差异会略有不同。

    【讨论】:

    • 感谢关于基于文件存在激活配置文件的想法,但是我的父项目只有一个 pom.xml 文件和一个目标目录,不足以(仅基于这些文件)来区分它来自子项目。还有其他想法吗? -
    • @Dave。您始终可以将目录(和/或文件)添加到 pom 项目中。
    【解决方案2】:

    我有类似的情况,我想默认在子项目中运行配置文件,但不是在从顶层构建时,同时提供从顶层项目运行的选项。

    我结合 Ryan 的参考使用了 user.dir 属性。

    集成项目的pom中:

        <profile>
            <id>continuous-integration</id>
            <!-- Two ways of activating this profile -->
            <activation>
                <!-- Run the build from the top with param -DfullTest -->
                <property>
                    <name>fullTest</name>
                </property>
                <!-- Run the build from the integration directory -->
                <file>
                    <missing>${user.dir}/integration</missing>
                </file>
            </activation>
        ...
        <profile>
    

    如果需要禁用,只需将&lt;missing/&gt; 更改为&lt;exists/&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 2018-07-18
      • 1970-01-01
      • 2011-07-09
      相关资源
      最近更新 更多