gpt4 book ai didi

java - 在版本 :prepare only 上运行 Maven 配置文件

转载 作者:太空宇宙 更新时间:2023-11-04 14:48:30 24 4
gpt4 key购买 nike

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

-Dresume=false clean release:prepare release:perform

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

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

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

有人可以帮助我找到可行的解决方案吗?

最佳答案

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

首先,添加执行所需工作的配置文件:

    <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>

最后一步是仅当文件不存在时才激活配置文件。请注意,在发布期间:执行的基本目录是 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>

关于java - 在版本 :prepare only 上运行 Maven 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24086380/

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