Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Maven clean phase be added to default lifecycle?

Tags:

java

maven

I have been using maven for some time and I am quite fond of it. But there are some minor annoyances that must be fixed I think.

There is this clean phase, I need to use it from time to time because there may be some old classes on the packaging file which brings chaotic errors on application server.

I know that when i execute the package phase, it runs all the other phases before it but not clean. Because clean is in clean lifecycle.

So is there any way to add clean to default lifecycle?

Thanks

like image 543
LostMohican Avatar asked Dec 11 '25 12:12

LostMohican


2 Answers

probably this can work

 <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <executions>
      <execution>
        <id>auto-clean1</id>
        <phase>initialize</phase>
        <goals>
          <goal>clean</goal>
        </goals>
      </execution>
      <execution>
        <id>auto-clean2</id>
        <phase>package</phase>
        <goals>
          <goal>clean</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
like image 112
Andrey Borisov Avatar answered Dec 14 '25 03:12

Andrey Borisov


I would not add clean to default lifecycle just to clean old compiled classes - it will break conventions of maven users. It is much easier to type mvn install or mvn clean install when required than trying to figure out why it always recompiles all from scratch and trying to skip that auto-cleanup.

like image 43
Andriy Plokhotnyuk Avatar answered Dec 14 '25 02:12

Andriy Plokhotnyuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!