Deep Dive: Maven Build Lifecycle & the Truth About -DskipTests

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5175

    #1

    Deep Dive: Maven Build Lifecycle & the Truth About -DskipTests

    A practical breakdown of what Maven does behind the scenes

    Introduction


    Why Every Java Developer Should Understand mvn clean install? Well

    Every Java developer types mvn clean installdozens of times a day. But how many of us actually know what happens behind the scenes?


    So let's check out


    First of all, mvn clean install executes two Maven lifecycle phases in sequence.


    clean Lifecycle


    Maven first runs the clean lifecycle, which has 3 phases:





    install Lifecycle (Default Lifecycle)


    Then Maven runs the default lifecycle up to the install phase, executing every phase in order:







    Diagram for Better Understanding :






    Does it skip tests?

    No — by default, mvn clean install does NOT skip tests. The test phase runs automatically.


    To skip tests, you have two options:






    # Skip test EXECUTION (but still compiles tests)
    mvn clean install -DskipTests

    # Skip test COMPILATION + execution entirely
    mvn clean install -Dmaven.test.skip=true










    Conclusion

    mvn clean installruns the clean lifecycle first, then the default lifecycle up to install

    Tests are a core part of the lifecycle and run by default — never skipped unless you explicitly ask

    -DskipTests is a Maven build property (not a JVM property) consumed by the Surefire Plugin

    -DskipTests skips execution only — test classes are still compiled

    Use -Dmaven.test.skip=true when you want the fastest possible build


    Disclaimer: This blog is based on my personal understanding and learning. There may be variations in the actual flow depending on your Maven version or project configuration. I encourage you to verify with the official Maven documentation. I hope this was helpful in your learning journey!


    Thank you so much for taking the time to read this blog. I hope it added some value to your learning journey!

    With regards,

    JavaCharter | Kailash

    Happy Coding! ☕💻




    More...
Working...