Question

I'm using buildnumber-maven-plugin to add the build number from the latest github commit to the name of the generated war:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <warName>${project.artifactId}-${buildNumber}</warName>
    <webResources>
      <resource>
        <directory>${project.basedir}/src/main/webapp/WEB-INF</directory>
        <filtering>true</filtering>
        <targetPath>WEB-INF</targetPath>
      </resource>
    </webResources>
  </configuration>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <version>1.2</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
   </execution>
  </executions>
  <configuration>
   <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
    <shortRevisionLength>6</shortRevisionLength>
  </configuration>
</plugin>
<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>${jetty.version}</version>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <war>target/${project.artifactId}-${buildNumber}.war</war>
    <webApp>
      <contextPath>/hope</contextPath>
      <descriptor>${basedir}/target/WEB-INF/web.xml</descriptor>
    </webApp>
    <connectors>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>8080</port>
        <maxIdleTime>60000</maxIdleTime>
      </connector>
    </connectors>
  </configuration>
</plugin>

This correctly creates a .war file with the first 6 characters of the commit id, and also works fine when running mvn jetty:run; however, when I run mvn jetty:run-war, I get the following output:

[INFO] Webapp assembled in [160 msecs]
[INFO] Building war: /home/jon/Projects/hope/hope/hope-web/target/hope-web-b242c0.war
[INFO] 
[INFO] --- maven-site-plugin:3.3:attach-descriptor (attach-descriptor) @ hope-web ---
[INFO] 
[INFO] <<< jetty-maven-plugin:9.0.5.v20130815:run-war (default-cli) @ hope-web <<<
[INFO] 
[INFO] --- jetty-maven-plugin:9.0.5.v20130815:run-war (default-cli) @ hope-web ---
[INFO] Configuring Jetty for project: Website
[INFO] Context path = /hope
[INFO] Tmp directory = /home/jon/Projects/hope/hope/hope-web/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
2013-10-29 12:49:34.920:INFO:oejs.Server:main: jetty-9.0.5.v20130815
2013-10-29 12:49:34.934:WARN:oejw.WebInfConfiguration:main: Web application not found /home/jon/Projects/hope/hope/hope-web/target/hope-web-${buildNumber}.war
2013-10-29 12:49:34.934:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@c638285{/hope,null,null}{/home/jon/Projects/hope/hope/hope-web/target/hope-web-${
buildNumber}.war}
java.io.FileNotFoundException: /home/jon/Projects/hope/hope/hope-web/target/hope-web-${buildNumber}.war

So, even though that process builds the .war file with the commit id, jetty looks for a war file with the buildnumber plugin property name.

How do I configure these plugins to work with one another?

Was it helpful?

Solution

Jon,

I'm not sure this is going to be possible.

The jetty:run-war goal will fork a parallel build execution to make sure that the war is built (ie the mojo has @execute phase="package"). The substitution of the ${buildNumber} within the pom occurs for that forked execution. It does not appear to be substituted for the execution that is running the jetty-maven-plugin (assuming it would be calculated the same way a second run). Not sure why that is, but certainly if I modify the jetty-maven-plugin to print out all of the properties known by the MavenProject representing its execution, the buildNumber is not present. However, it is present on the properties represented by the forked MavenProject. May be something to ask the buildnumber-maven-plugin project about?

BTW I even tried changing your example a little by setting: <finalName>${project.artifactId}-${buildNumber}</finalName>

That means you can remove the <warName> from the maven-war-plugin setting. I was hoping that it would also set the <finalName> value of the execution for the jetty-maven-plugin, but no such luck.

cheers Jan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top