Last active
November 1, 2019 03:10
-
-
Save jamestrandung/70b4cfd64ba2c20fb16d053126590164 to your computer and use it in GitHub Desktop.
POM for creating WAR with React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> | |
<artifactId>monolithic</artifactId> | |
<packaging>war</packaging> | |
<parent> | |
<groupId>com.ft</groupId> | |
<artifactId>workforce-optimizer</artifactId> | |
<version>1.0.0-RELEASE</version> | |
<relativePath>../pom.xml</relativePath> | |
</parent> | |
<properties> | |
<java.version>1.8</java.version> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<ui.directory>${basedir}/ui</ui.directory> | |
<webapp.directory>${basedir}/src/main/webapp/</webapp.directory> | |
<react.source.directory>${ui.directory}/front-end</react.source.directory> | |
<npm.output.directory>dist</npm.output.directory> | |
<!-- By default, the WAR will be generated to run at /wfo context path. | |
This context path can be set to another value by providing the | |
command line argument -Ddeployment.context.path when running Maven | |
build/package/install. --> | |
<deployment.context.path>/wfo</deployment.context.path> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>com.ft</groupId> | |
<artifactId>common-core</artifactId> | |
<version>1.1.0-RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>com.ft</groupId> | |
<artifactId>schedule</artifactId> | |
<version>1.0.0-RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-validation</artifactId> | |
</dependency> | |
<!-- DEPENDENCIES TO EXCLUDE - They still take effect while running directly | |
from IDE via right-click -> Run. However, at run-time, in standalone servlet | |
container environment, these dependencies do not exist unless provided directly | |
by the container. --> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-tomcat</artifactId> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | |
<scope>provided</scope> | |
</dependency> | |
<!-- DEPENDENCIES TO EXCLUDE --> | |
</dependencies> | |
<build> | |
<finalName>wfo</finalName> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
<!-- The configuration below together with the packagingExcludes settings | |
for maven-war-plugin are required to prevent our JARs from being included | |
in the final WAR. We already unpacked these JARs, no need to include them. --> | |
<configuration> | |
<excludeGroupIds>com.ft</excludeGroupIds> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-war-plugin</artifactId> | |
<configuration> | |
<packagingExcludes> | |
WEB-INF/lib/schedule-*.jar, | |
WEB-INF/lib/common-core-*.jar, | |
</packagingExcludes> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>exec-maven-plugin</artifactId> | |
<executions> | |
<!-- Trigger building the front-end project --> | |
<execution> | |
<id>npm run build (compile)</id> | |
<goals> | |
<goal>exec</goal> | |
</goals> | |
<phase>compile</phase> | |
<configuration> | |
<executable>npm</executable> | |
<arguments> | |
<argument>run</argument> | |
<argument>--prefix</argument> | |
<argument>${react.source.directory}</argument> | |
<argument>build-war</argument> | |
<!-- Feed the provided context path into the REACT_APP_CONTEXT_PATH npm config | |
variable configured for the build-war script inside package.json. --> | |
<argument>--REACT_APP_CONTEXT_PATH=${deployment.context.path}</argument> | |
</arguments> | |
</configuration> | |
</execution> | |
</executions> | |
<configuration> | |
<environmentVariables> | |
<CI>true</CI> | |
The following parameters create an NPM sandbox for CI | |
<NPM_CONFIG_PREFIX>${ui.directory}/npm</NPM_CONFIG_PREFIX> | |
<NPM_CONFIG_CACHE>${NPM_CONFIG_PREFIX}/cache</NPM_CONFIG_CACHE> | |
<NPM_CONFIG_TMP>${ui.directory}/npmtmp</NPM_CONFIG_TMP> | |
</environmentVariables> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<!-- Delete the previous compiled front-end code from webapp folder --> | |
<execution> | |
<id>delete the content of webapp folder</id> | |
<phase>prepare-package</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<target> | |
<delete includeemptydirs="true" | |
failonerror="false"> | |
<fileset dir="${webapp.directory}" | |
includes="**/*" /> | |
</delete> | |
</target> | |
</configuration> | |
</execution> | |
<!-- Move the new compiled front-end code into webapp folder --> | |
<execution> | |
<id>move compiled react code into webapp</id> | |
<phase>prepare-package</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<target> | |
<move todir="${webapp.directory}"> | |
<fileset | |
dir="${react.source.directory}/${npm.output.directory}" /> | |
</move> | |
</target> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-dependency-plugin</artifactId> | |
<executions> | |
<!-- By default, our projects are included in the WAR file as JAR | |
artifacts. This is inconvenient as we need to update the config files for | |
each customer after building the WAR. Hence, we need to take an extra step | |
and unpack all of our JARs to expose the config files. --> | |
<execution> | |
<id>unpack our own JARs to expose the config files</id> | |
<phase>initialize</phase> | |
<goals> | |
<goal>unpack</goal> | |
</goals> | |
<configuration> | |
<artifactItems> | |
<artifactItem> | |
<groupId>com.ft</groupId> | |
<artifactId>schedule</artifactId> | |
<type>jar</type> | |
<overWrite>false</overWrite> | |
</artifactItem> | |
<artifactItem> | |
<groupId>com.ft</groupId> | |
<artifactId>common-core</artifactId> | |
<type>jar</type> | |
<overWrite>false</overWrite> | |
</artifactItem> | |
</artifactItems> | |
<includes>**/*</includes> | |
<excludes>**/standalone-service-config.yml,**/Application.class,**/application_test.properties,**/jwt.jks,**/sample-application.yml,**/MANIFEST.MF,**/*_dev.yml</excludes> | |
<outputDirectory>${project.build.outputDirectory}</outputDirectory> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
<profiles> | |
<profile> | |
<id>wfo-war</id> | |
<activation> | |
<activeByDefault>true</activeByDefault> | |
</activation> | |
</profile> | |
</profiles> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment