Storm
Storm

Reputation: 73

Remove folder during maven generate-sources or maven install

I'm trying delete folder before execute the generate-sources or install. I'm already doing this during the clean with the folders under src/main/java, but I wanted to try also in a different moment, just because I'm sure that is impossible to forget to delete some file/folder. How do this?

Upvotes: 2

Views: 2227

Answers (1)

Gerold Broser
Gerold Broser

Reputation: 14762

See the example at Apache Maven Clean Plugin / Delete Additional Files Not Exposed to Maven.

  • Adapt the <configuration> section given there according to your needs and with:

                        ...
                        <directory>src/main/java</directory>
                        ...
    
  • Add an <executions> section like:

        ...
        <plugin>
            ...
            <executions>
                <execution>
                    <id>delete-files</id>
                    <!-- 'initialize' is the phase before 'generate-sources'
                          use 'verify' to execute it before 'install' -->
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
            ...
    

The result will be:

...
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (delete-files) @ so-51708371 ---
[INFO] Deleting ...path to workspace...\so-51708371\target
[INFO] Deleting ...path to workspace...\so-51708371\src\main\java (includes = [**/*.tmp, **/*.log], excludes = [**/important.log, **/another-important.log])
[INFO]
...

Upvotes: 2

Related Questions