Maven clean plugin exclude .cvsignore

2019-07-16 05:15发布

问题:

In my project I originally made a mistake and committed the target directory in the cvs repository; I know there is no safe way to remove a directory from CVS, so I put a .cvsignore file there to basically ignore everything (I don't want developers who aren't able to even merge properly to commit their classes...).

The problem raises with my Jenkins CI, because I run clean and test goals; basically clean is run before CVS update, so it always finds a file to update (the .cvsignore that has been wiped by clean) and triggers an often useless build.

I think the way to go is to use exclusions but I tried and did not work:

[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: **************************/target (included: [**], excluded: [])

The exclusion is configured as:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
        <execution>
            <id>not-clean</id>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>target</directory>
                        <excludes>
                            <exclude>*cvsignore</exclude>
                        </excludes>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
            </configuration>
            <phase>initialize</phase>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
    </executions>
</plugin>

回答1:

You could try setting <excludeDefaultDirectories> to true, Otherwise, I believe target folder would always get deleted.

The following code snippet works for me. Note that I have used default-clean as the id.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <id>default-clean</id>
                    <configuration>
                        <excludeDefaultDirectories>true</excludeDefaultDirectories>
                        <filesets>
                            <fileset>
                                <directory>target</directory>
                                <excludes>
                                    <exclude>.cvsignore</exclude>
                                    <exclude>CVS</exclude>
                                    <exclude>CVS/**</exclude>
                                </excludes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                        </filesets>
                    </configuration>
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>