views:

592

answers:

2

We use Hudson, Maven2 and maven-ear-plugin.

Is it possible to have the built EAR files to contain SVN revision in their filename (something like project-1234.ear)?

A: 

Hudson nows the revision. So you have two options. Just rename the output afterwards or supply Maven with the revision and it can change the name as needed.

Thinkking about it, there might also be another way. Let Maven query svn for the revision and than incorporate it in the earname


However, Do you really need it? Hudson offers the option to fingerprint ears. This way you can submit the file later to Hudson and it gives the the build number back.

Peter Schuetze
Relying on the CI engine for this is not a good idea IMO. The CI tool should be used to trigger the build and for notification, not for things that should be handled at the build level (what if you build outside of hudson, what if you use another CI tool, etc).
Pascal Thivent
Depends on the requirements. Do you end up with misleading filenames if you build uncommitted code? -- However, I agree that you should be careful when using the CI engine for this. However, in my particular use case, we established the CI engine as the authoritative building engine. Which means all binaries that will be deployed to a central environment have to be created by the CI engine. This makes test results more reproduceable. Since you eliminate problems resulting from different settings at compile time.
Peter Schuetze
+1  A: 

You can use the buildnumber-maven-number for this. Basically, this plugin sets a ${buildNumber} property that you can use later in the maven ear plugin configuration.

First, setup the Build Number Maven Plugin as documented here:

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

Then, use the finalName parameter to customize the name of the generated ear. For example:

<plugins>
  ...
  <plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.4</version>
    <configuration>
      <finalName>${project.artifactId}-r${buildNumber}</finalName> 
      ...
    </configuration>
  </plugin>
  ...
</plugins>
Pascal Thivent