PassoGiau
PassoGiau

Reputation: 617

Modifying jar filename using maven

I have a requirement that all the artifacts created by maven bear a build number. The build number is stored in a properties file. I'm successful with controlling the names of generated EAR and WAR artifacts but not the JAR. Here are the relevant excerpts from pom.xml. I expected the maven-jar-plugin configuration to work but it does not, I end up with jar always named SelfService-2.jar, whereas when buildNumber.properties contains buildNumber=40, maven generates SelfService-2.40.war and SelfService-2.40.ear.

How do I get the build number into the jar name? Thanks in advance.

<artifactId>SelfService</artifactId>
<name>SelfService</name>
<packaging>war</packaging>
<version>2</version>

<build>
  <finalName>${project.artifactId}-${buildNumber}</finalName>
  <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <finalName>${project.artifactId}-${buildNumber}</finalName>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <finalName>${project.artifactId}-${buildNumber}</finalName>
        </configuration>
      </plugin>
      ....

Upvotes: 1

Views: 4713

Answers (1)

PassoGiau
PassoGiau

Reputation: 617

I got what I was after by using the following configuration of maven-jar-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
     <version>2.3.2</version>
     <executions>
        <execution>
           <phase>package</phase>
        <goals>
            <goal>jar</goal>
        </goals>
        <configuration>
            <finalName>${project.artifactId}-${buildNumber}</finalName>
        </configuration>
        </execution>
    </executions>
    <configuration>
        <finalName>${project.artifactId}-${buildNumber}</finalName>
    </configuration>
 </plugin>

Upvotes: 1

Related Questions