【问题标题】:Running a maven profile on release:prepare only在发布时运行 Maven 配置文件:仅准备
【发布时间】:2014-06-06 16:14:58
【问题描述】:

我正在通过 jenkins 调用 maven 来启动发布过程

-Dresume=false clean release:prepare release:perform

由于我想在准备过程完成之前更改源代码(添加目录和文件并将它们提交到 git),因此我想仅在 release:prepare 阶段运行配置文件“doAtPrepare”。该配置文件已经在正确的位置工作,但不幸的是调用了两次。一次在发布:准备和一次在发布:执行阶段。后者在 git 提交“分离头”时会产生错误。

对于在 release:perform 阶段运行配置文件,maven-release-plugin 中只有配置选项“releaseProfiles”有效。但是我反过来需要它,到目前为止还没有找到解决方案。

我尝试使用 profile.activation.properties (profile=!doAtPrepare),尝试设置变量 (-D) 并使用 profile.activation.properties 检查它们,尝试检查 profile.activation.file 中的现有文件(其中不起作用,因为文件名包含 ${version} 参数),尝试在 jenkins 命令行中使用 -P (这会在两个阶段触发配置文件)等等。

有谁能帮我找到可行的解决方案吗?

【问题讨论】:

    标签: java git maven jenkins


    【解决方案1】:

    我找到了解决方法,但不是真正的解决方案。仍然欢迎更好的建议。

    首先,添加一个完成所需工作的配置文件:

        <profile>
            <id>createNextDir</id>
            <build>
                <plugins>
                    <plugin>
                        <!-- whatever you want -->
                    </plugin>
                </plugins>
            </build>
        </profile>
    

    接下来,向配置文件添加一个作业,该作业在您的目标目录中创建一个具有固定文件名的虚拟文件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <id>createNextDir1</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <target>
                        <propertyfile file="target/done.lock" comment="Version ${project.version}">
                        </propertyfile>
                    </target>
                </configuration>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>ant-contrib</groupId>
                <artifactId>ant-contrib</artifactId>
                <version>20020829</version>
            </dependency>
        </dependencies>
    </plugin>
    

    最后一步是仅在文件不存在时激活配置文件。请注意,在 release:perform 期间,基本目录是 target/checkout/yourproject,因此需要引用正确的文件 ../../../yourproject/target/done.lock

    <profile>
        <id>createNextDir</id>
        <activation>
            <file>
                <missing>../../../yourproject/target/done.lock</missing>
            </file>
        </activation>
        <!-- Rest of profile -->
    </profile>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多