在 mvn clean package 期间仅构建 WAR 一次
Build WAR only once during mvn clean package
我有一个应该构建 war 文件的 Maven 项目。当我 运行 mvn clean package
时,我在日志中看到一开始它是默认的-war:
--- maven-war-plugin:2.3:war (default-war) @ my-artifact---
Packaging webapp
然后它使war:
--- maven-war-plugin:2.3:war (war) @ my-artifact---
Packaging webapp
我的 pom.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.group</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>my-artifact</artifactId>
<packaging>war</packaging>
<dependencies>
<...>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
<Build-Time>${timestamp}</Build-Time>
<Implementation-Revision>${myapp.revision}</Implementation-Revision>
<Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
<Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
</manifestEntries>
</archive>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
<executions>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
所以我想要的是禁用默认构建-war。
您应该从 maven-war-plugin
配置中删除 <executions>
标签。默认情况下,此插件将在打包阶段执行,无需任何配置。这将是正确的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
<Build-Time>${timestamp}</Build-Time>
<Implementation-Revision>${myapp.revision}</Implementation-Revision>
<Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
<Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
</manifestEntries>
</archive>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
我有一个应该构建 war 文件的 Maven 项目。当我 运行 mvn clean package
时,我在日志中看到一开始它是默认的-war:
--- maven-war-plugin:2.3:war (default-war) @ my-artifact---
Packaging webapp
然后它使war:
--- maven-war-plugin:2.3:war (war) @ my-artifact---
Packaging webapp
我的 pom.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.group</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>my-artifact</artifactId>
<packaging>war</packaging>
<dependencies>
<...>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
<Build-Time>${timestamp}</Build-Time>
<Implementation-Revision>${myapp.revision}</Implementation-Revision>
<Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
<Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
</manifestEntries>
</archive>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
<executions>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
所以我想要的是禁用默认构建-war。
您应该从 maven-war-plugin
配置中删除 <executions>
标签。默认情况下,此插件将在打包阶段执行,无需任何配置。这将是正确的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
<Build-Time>${timestamp}</Build-Time>
<Implementation-Revision>${myapp.revision}</Implementation-Revision>
<Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
<Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
</manifestEntries>
</archive>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>