5
votes

I have a maven question.

I have a GWT project which generates a temporary directory gwt-unitCache folder. I'd like to remove it at the end of the build process.

I have got this plugin configuration:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main</directory>
                <includes>
                    <directory>gwt-unitCache/**</directory>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
        </execution>
    </executions>
</plugin>

This does its job by deleting the automatically generated gwt-unitCache folder under src/main. However, it also removed the target folder which contains the classes and war file.

I don't want the target file to be removed thus I modified the configuration by removing the section:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main</directory>
                <includes>
                    <directory>gwt-unitCache/**</directory>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
        </execution>
    </executions>
</plugin>

But this time it does not work anymore. The gwt-unitCache is not removed. It looks like the plugin is run at the beginning of the build process rather than at the end.

I am not good at Maven. Can someone help with this? How can I configure it so that:

  1. The gwt-unitCache is removed at the end of the build process.
  2. The target folder is not removed.

I use the command: maven clean install

to build it.

Many thanks.

3

3 Answers

6
votes

Not tested but maven-clean-plugin exposes an excludeDefaultDirectories that could help do the job. Something like:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main</directory>
                <includes>
                    <directory>gwt-unitCache/**</directory>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
        <excludeDefaultDirectories>true</excludeDefaultDirectories>
    </configuration>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
    </executions>
</plugin>

On a side note, I don't see why you need to clear this directory, can't you just ignore it in your SCM?

0
votes

RC I use this variation to still working as usual on clean phase.

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
            <goals>
                <goal>clean</goal>
            </goals>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>${project.build.directory}/${project.build.finalName}/c</directory>
                        <includes>
                            <directory>gwt-unitCache/**</directory>
                        </includes>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
                <excludeDefaultDirectories>true</excludeDefaultDirectories>
            </configuration>
        </execution>
    </executions>
</plugin>
0
votes

Since it came up in a comment: You can change the location of the cache directory like this:

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>gwt-maven-plugin</artifactId>

 <configuration>
   <persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
 </configuration>
</plugin>