0
votes

I use maven to build some projects which are installed into local .m2 and a remote artifactory repository.

I have another project that downloads (maven-dependency-plugin:copy) some of these artifacts to its local target folder and then uploads them to a fileshare. When I upload the artifact to fileshare I need to give it a buildNumber which should not change if I re-run the project. How do I get the buildnumber for a artifact in eg. artifactory?

When I browse the artifacts in artifactory they all have unique buildIds.

1
Why not using the version of the artifact? - khmarbaise
Its SNAPSHOT versions so there are no guarantee that the artifacts are identical, which is the point of snapshots, but I need to get the specific build in the above scenario - u123

1 Answers

0
votes

The best solutin might be to use buildnumber-maven-plugin to get the information from VCS etc. and put this information into the manifest.mf file. You can continue using the maven-dependency-plugin:copy goal to copy artifacts into the appropriate folder. Only in case you have SNAPSHOT's you might later take a look into the jar itself.

 <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <doCheck>true</doCheck>
          <doUpdate>true</doUpdate>
        </configuration>
      </plugin>
    </plugins>
  </build>

You can define what should be put into the MANIFEST.MF file like the following:

<build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
            <manifestEntries>
              <Implementation-Build>${buildNumber}</Implementation-Build>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>