Search code examples
mavenmaven-3maven-war-plugin

How do I change the Maven-WAR plugin's cache file location?


I’m using Maven 3.1.1 and using the Maven-war plugin v 2.4. I would like to create the cache in a directory other than the ${basedir}/target/war/work directory, but I can’t seem to figure out how to configure the plugin to do that. I tried

                            <plugins>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-war-plugin</artifactId>
                                            <version>2.4</version>
                                            <configuration>
                                                    <useCache>true</useCache>
                                                    <workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
                                            </configuration>
                                            <goals>
                                                    <goal>inplace</goal>
                                            </goals>
                                    </plugin>
                            </plugins>

However, the work directory never changes. Any idea how to configure things so that the plugin respects where I want to place the cache file?


Solution

  • I'm going to explain what i discovered with the help of the debug flag (mvn -X clean install).

    Default values are:

    <workDirectory default-value="${project.build.directory}/war/work"/>
    <cacheFile default-value="${project.build.directory}/war/work/webapp-cache.xml"/>
    

    As stated in maven war plugin's doc, workDirectory parameter is where where overlays will be temporarily extracted; changing it will not affect the path of the cache's file.

    Instead, adding a cacheFile tag to configuration

    <configuration>
      <useCache>true</useCache>
      <cacheFile>/customdir/webapp-cache.xml</cacheFile>
    </configuration>
    

    will override the cache's final position, resulting in:

    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-war-plugin:2.4:war' with basic configurator -->
    [DEBUG]   (s) archiveClasses = false
    [DEBUG]   (s) attachClasses = true
    [DEBUG]   (s) cacheFile = C:\customdir\webapp-cache.xml
    

    Regards, PaoloC