我的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.example</groupId>
<artifactId>test-application</artifactId>
<packaging>war</packaging>
<version>0.2.0</version>
<profiles>
<profile>
<id>local</id>
<activation>
<property>
<name>envType</name>
<value>local</value>
</property>
</activation>
<properties>
<envType>local</envType>
</properties>
</profile>
<profile>
<id>local2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<envType>local2</envType>
</properties>
</profile>
<profile>
<id>dev</id>
<activation>
<property>
<name>envType</name>
<value>dev</value>
</property>
</activation>
<properties>
<envType>dev</envType>
</properties>
</profile>
<profile>
<id>sit</id>
<activation>
<property>
<name>envType</name>
<value>sit</value>
</property>
</activation>
<properties>
<envType>sit</envType>
</properties>
</profile>
<profile>
<id>uat</id>
<activation>
<property>
<name>envType</name>
<value>uat</value>
</property>
</activation>
<properties>
<envType>uat</envType>
</properties>
</profile>
</profiles>
<build>
<finalName>my-application</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v6.10.0</nodeVersion>
<npmVersion>3.10.10</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>gulp build</id>
<goals>
<goal>gulp</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>optimize --env ${envType}</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
前端maven插件安装节点,所有必需的npm和bower包,并启动gulp任务以优化所有前端代码。 Gulp将所有前端代码放在下面 -
/src/main/webapp/index.html
/src/main/webapp/js/
etc
web.xml位于 -
/src/main/webapp/WEB-INF/web.xml
为本地,SIT,DEV等环境构建war包的命令 -
mvn clean install -DenvType=local
mvn clean install -DenvType=sit
mvn clean install -DenvType=uat
这会在my-application.war
目录中构建war文件 - /target
。
我需要每次单独运行maven命令,以便为每个环境构建war包。 (因为前端代码为每个环境使用单独的环境变量)。
如何更改构建过程以便我只需构建一次,maven就会依次为每个环境(gulp optimize --env ${envType}
)运行gulp任务,并在目标目录中生成单独的war文件 -
my-application-local.war
my-application-sit.war
my-application-uat.war
etc
我需要maven按顺序运行gulp任务。我可以让每次运行gulp将前端代码输出到单独的目录。 maven应该从这些单独的目录中选择并创建单独的war文件。不确定这是否是正确的方法。请告诉我。