ANT : What is the simplest way to add version number to built jar?

放肆的年华 提交于 2020-01-04 03:59:29

问题


<?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 &#39;myPlugin:jar&#39; 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" />

回答1:


The simplest solution is to use the ANT buildnumber task.

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


来源:https://stackoverflow.com/questions/14759755/ant-what-is-the-simplest-way-to-add-version-number-to-built-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!