Maven - how to delete contents of a folder during a clean phase?

后端 未结 5 743
迷失自我
迷失自我 2021-01-01 08:32

in my project I have a folder called war. It is initially empty and it\'s under version control. The folder gets populated by Maven during its package

相关标签:
5条回答
  • 2021-01-01 09:10

    If you wan to delete more than one directory recursively:

        <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>auto-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>${basedir}</directory>
                                    <includes>**/dir1/**</includes>
                                </fileset>
                                <fileset>
                                    <directory>${basedir}</directory>
                                    <includes>**/dir2/**</includes>
                                </fileset>
                                <fileset>
                                    <directory>${basedir}</directory>
                                    <includes>**/dir3/**</includes>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    0 讨论(0)
  • 2021-01-01 09:29

    In my case I needed to delete the "bin" directory, and all it's subdirectory contents. I did this in my parent pom.xml:

    <fileset>
        <directory>${basedir}</directory>
          <includes>
            <include>**/bin/**</include>
          </includes> 
          <followSymlinks>false</followSymlinks>
    </fileset>
    

    This found any bin directory within my project, and deleted any contents of the bin folder.

    0 讨论(0)
  • 2021-01-01 09:31

    Add this includes section to your fileset definition

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>war</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
  • 2021-01-01 09:33

    to delete folder from src/main/webapp/folder use :

    <configuration>
      <filesets>
        <fileset>
          <directory>src/main/webapp</directory>
          <includes>
            <include>folder/</include>
          </includes>
          <followSymlinks>false</followSymlinks>
        </fileset>
      </filesets>
    </configuration>
    
    0 讨论(0)
  • 2021-01-01 09:35

    You will have to use the maven ant plugin & add the task to delete the folder contents only. However why do you need the war file in version control? Every time you build your code base will show that there are some modifications/new files (classes generated) to be checked in. If you are using standard maven conventions the target folder is used for all output.

    0 讨论(0)
提交回复
热议问题