1

我正在使用 buildnumber-maven-plugin 将最新 github 提交中的内部版本号添加到生成的战争的名称中:

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

这正确地创建了一个带有提交 ID 前 6 个字符的 .war 文件,并且在运行时也可以正常工作mvn jetty:run;但是,当我运行时mvn jetty:run-war,我得到以下输出:

[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

因此,即使该过程使用提交 ID 构建 .war 文件,jetty 也会查找具有 buildnumber 插件属性名称的 war 文件。

如何配置这些插件以相互配合?

4

1 回答 1

0

乔恩,

我不确定这是否可行。

jetty:run-war 目标将分叉并行构建执行以确保构建战争(即 mojo 具有 @execute phase="package")。pom 中的 ${buildNumber} 替换发生在该分叉执行中。它似乎没有替代运行 jetty-maven-plugin 的执行(假设它的计算方式与第二次运行相同)。不知道为什么会这样,但可以肯定的是,如果我修改 jetty-maven-plugin 以打印出 MavenProject 已知的代表其执行的所有属性,则 buildNumber 不存在。但是,它存在于由分叉的 MavenProject 表示的属性上。可能需要询问 buildnumber-maven-plugin 项目吗?

顺便说一句,我什至尝试通过设置更改您的示例: <finalName>${project.artifactId}-${buildNumber}</finalName>

这意味着您可以从 maven-war-plugin 设置中删除 <warName> 。我希望它也会为 jetty-maven-plugin 设置执行的 <finalName> 值,但没有这样的运气。

欢呼一月

于 2013-11-28T05:10:22.607 回答