gpt4 book ai didi

java - 使用 jenkins 构建 netbeans 项目时,如何在 list 文件中设置版本信息?

转载 作者:行者123 更新时间:2023-12-01 08:55:08 26 4
gpt4 key购买 nike

我有一个使用 netbeans IDE 构建的项目(如果我没记错的话,内部使用 Ant 构建)

我们使用的CI服务器是jenkins。我想将版本信息添加到生成的 jar 的 list 中。

我该怎么做?

最佳答案

假设您的 Jenkins 构建过程以某种方式更新项目版本,可能的解决方案是:

nbproject\build-impl.xml中添加 list 条目

<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" ...
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
<!-- add this line below -->
<attribute name="Project-Version" value="${project.version}"/>
</manifest>
</target>

nbproject\project.properties中添加项目版本

project.version=0.0.1-SNAPSHOT

构建

ant jar

输出

$ unzip -p dist/CI-test.jar META-INF/MANIFEST.MF | grep Project
Project-Version: 0.0.1-SNAPSHOT

编辑:使用环境变量的另一种解决方案。

nbproject\build-impl.xml中使用环境变量PROJECT_VERSION添加 list 条目

<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" ...
<!-- enable access to environment variables -->
<property environment="env"/>
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
<!-- add this line below -->
<attribute name="Project-Version" value="${env.PROJECT_VERSION}"/>
</manifest>
</target>

构建

# define the environment variable
# on Windows use: set PROJECT_VERSION=0.0.2-SNAPSHOT
PROJECT_VERSION=0.0.2-SNAPSHOT
ant jar

输出

$ unzip -p dist/CI-test.jar META-INF/MANIFEST.MF | grep Project
Project-Version: 0.0.2-SNAPSHOT

关于java - 使用 jenkins 构建 netbeans 项目时,如何在 list 文件中设置版本信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42082223/

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