java ANT:将版本号添加到构建的 jar 的最简单方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14759755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:18:34 来源:igfitidea点击:
ANT : What is the simplest way to add version number to built jar?
提问by stackoverflow
<?xml version="1.0" encoding="UTF-8"?>
<project name="myPlugin" default="all">
<target name="artifact.myPlugin:jar" depends="init.artifacts, compile.module.myPlugin" description="Build 'myPlugin:jar' artifact">
<mkdir dir="${artifact.output.myplugin:jar}" />
<jar destfile="${temp.jar.path.myPlugin.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
<zipfileset file="${basedir}/META-INF/MANIFEST.MF" prefix="META-INF" />
<zipfileset dir="${myPlugin.output.dir}" />
</jar>
<!--How would I add a version number to this that reflects my projects version -->
<copy file="${temp.jar.path.myPlugin.jar}" tofile="${artifact.output.myPlugin:jar}/plugin.company.jar" />
</target>
What is the typcial way that people do this?
人们这样做的典型方式是什么?
Example (Pulled from above)
示例(从上方拉出)
<copy file="${temp.jar.path.myPlugin.jar}" tofile="${artifact.output.myPlugin:jar}/plugin.company{version}.jar" />
回答by Mark O'Connor
The simplest solution is to use the ANT buildnumbertask.
最简单的解决方案是使用 ANT buildnumber任务。
<project name="myPlugin" default="all">
<property name="version" value="1.0"/>
<target...
<buildnumber/>
<jar destfile="/path/to/jar/myjar-${version}.${build.number}.jar" ...
...
</jar>
</target>
</project>
Each build will generate a unique release number:
每个构建都会生成一个唯一的版本号:
- myjar-1.0.0
- myjar-1.0.1
- myjar-1.0.2
- ..
- myjar-1.0.0
- myjar-1.0.1
- myjar-1.0.2
- ..