1) Use any Maven plugin that is able to copy and rename resources. For example, copy-rename-maven-plugin. Configure the plugin to copy all static resources which you want to version and put them into a new directory inside the target directory, for example target/static_versioned:
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>copy-file</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<sourceFile>src/main/webapp/css/style.css</sourceFile>
<destinationFile>target/static_versioned/css/style_${project.version}.css</destinationFile>
</fileSet>
<fileSet>
<sourceFile>src/main/webapp/js/app.js</sourceFile>
<destinationFile>target/static_versioned/js/app_${project.version}.js</destinationFile>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
2) Configure maven-war-plugin to add versioned static files inside you war file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webResources>
<resource>
<directory>target/static_versioned</directory>
</resource>
</webResources>
</configuration>
</plugin>
3) Maven copies both versioned and original files into the result war file, so the original files need to be excluded:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<packagingExcludes>**/css/style.css,**/js/app.js</packagingExcludes>
<webResources>
<resource>
<directory>target/static_versioned</directory>
</resource>
</webResources>
</configuration>
</plugin>
It is worth mentioning that the target directory still has original and versioned files, but the war file contains only versioned files.
4) Use maven-war-plugin's filtering functionality to rename static resource links so all links point to versioned resources:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<packagingExcludes>**/css/style.css,**/js/app.js</packagingExcludes>
<webResources>
<resource>
<directory>target/static_versioned</directory>
</resource>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
For example, a link like <script type="text/javascript" src="js/app_${project.version}.js"></script>
will be renamed into <script type="text/javascript" src="js/app_1.0-SNAPSHOT.js"></script>
Complete example is here: https://github.com/dmitrysobolev/maven-war-plugin-js-versioning-example