Asanke
Asanke

Reputation: 601

How to delete project folders outside the usual maven clean phase

This might sound bit off, but here is what I want;

I have a project that generates files in my target directory (so as every average project). I have configured maven clean to be executed in every build using the below.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>auto-clean</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    <plugins>
<build>

I also have couple of other folders outside target (I have deliberately opted to ) which store logs and test reports. These I do not want to clean in every run as I want them to refer for a certain period.

The project roughly looks like below.

Project
|--src/main/java
|--src/test/java
|--target
|--logs*
+--reports*

Here the logs and reports are the folders I want to prevent getting deleted in every run. I was able to manage the part that the report and logs folders not getting deleted in every run. ( pretty straight forward, don't mention of the two folders in your build)

However, I also need to have a maven command to delete these two special folders once in a while. How can I do that ?

Upvotes: 1

Views: 155

Answers (1)

VonC
VonC

Reputation: 1323343

You could consider adding a profile in which you set a different clean process:

<profiles>
  <profile>
  <id>cleanLogs</id>

  <build>...</build>

  </profile>
</profiles>

Calling it with mvn clean -PcleanLog would call that specific build process.
See also this tutorial on maven profiles.

Upvotes: 2

Related Questions