Java – ant: what is the easiest way to add a version number to a build jar?

<?xml version="1.0" encoding="UTF-8"?>
<?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 typical way people do this?

Example (pull out from above)

<copy file="${temp.jar.path.myPlugin.jar}" tofile="${artifact.output.myPlugin:jar}/plugin.company{version}.jar" />

Solution

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 generates a unique version number:

> myjar-1.0. 0> myjar-1.0. 1> myjar-1.0. 2> ..

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>