0

I have a project built using the netbeans IDE (Internally uses Ant to build if I am not mistaken)

The CI server we use is jenkins. I would like to add version info to the manifest for the jar that is produced.

How do I do that?

Tim
  • 20,184
  • 24
  • 117
  • 214

1 Answers1

1

Assuming that your Jenkins build process somehow update the project version a possible solution is:

in nbproject\build-impl.xml add an entry for the manifest

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

in nbproject\project.properties add the project version

project.version=0.0.1-SNAPSHOT

build

ant jar

output

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

edit: Another solution using an environment variable.

in nbproject\build-impl.xml add an entry for the manifest using the environment variable PROJECT_VERSION

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

build

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

output

$ unzip -p dist/CI-test.jar META-INF/MANIFEST.MF | grep Project
Project-Version: 0.0.2-SNAPSHOT
SubOptimal
  • 22,518
  • 3
  • 53
  • 69