Question

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?

Was it helpful?

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

OTHER TIPS

Declaring goals directly under plugin is deprecated. Please use:

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

(Note the executions tag).

I haven't tried this myself, but I think the problem is that you're not associating that execution with a phase. By default the inplace goal is not associated with any phase (unlike war which is associated to the package phase)

you can try the following

<executions>
   <execution>
      <phase>package</phase>
      <goals>
         <goal>inplace</goal>
      </goals>
      <configuration>
         <useCache>true</useCache>
         <workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
      </configuration>
   </execution>
</executions>  

This should trigger the inplace goal when maven executes the package phase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top