<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sai Upadhyayula</title>
    <description>The latest articles on DEV Community by Sai Upadhyayula (@saiupadhyayula).</description>
    <link>https://dev.to/saiupadhyayula</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F141300%2F88e39d97-a705-43e5-a605-f5c3cd368381.jpg</url>
      <title>DEV Community: Sai Upadhyayula</title>
      <link>https://dev.to/saiupadhyayula</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saiupadhyayula"/>
    <language>en</language>
    <item>
      <title>Junit 5 Tutorial for Beginners</title>
      <dc:creator>Sai Upadhyayula</dc:creator>
      <pubDate>Sun, 03 Jan 2021 11:27:57 +0000</pubDate>
      <link>https://dev.to/saiupadhyayula/junit-5-tutorial-for-beginners-o8a</link>
      <guid>https://dev.to/saiupadhyayula/junit-5-tutorial-for-beginners-o8a</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post was originally published in &lt;a href="https://programmingtechie.com/" rel="noopener noreferrer"&gt;programmingtechie.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Junit 5 is one of the popular testing frameworks in the Java Development World and it supports the latest features of Java 8.&lt;/p&gt;

&lt;p&gt;If you are a visual learner like me, check out the below video tutorial:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/bx-ZtLbGDHw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Junit 5 Architecture

&lt;ul&gt;
&lt;li&gt;Junit Platform&lt;/li&gt;
&lt;li&gt;Junit Jupiter&lt;/li&gt;
&lt;li&gt;Junit Vintage&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Source Code for Project under Test

&lt;ul&gt;
&lt;li&gt;Source Code for Starter Project&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Writing our First Test&lt;/li&gt;

&lt;li&gt;Testing Exceptions using assertThrows()&lt;/li&gt;

&lt;li&gt;

Understanding Test Lifecycle

&lt;ul&gt;
&lt;li&gt;Implementing Lifecycle Annotations in our Test&lt;/li&gt;
&lt;li&gt;@BeforeAll and @AfterAll&lt;/li&gt;
&lt;li&gt;@BeforeEach and @AfterEach&lt;/li&gt;
&lt;li&gt;Default Test Instance Lifecycle&lt;/li&gt;
&lt;li&gt;Changing Default Test Instance Lifecycle&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Conditional Executions&lt;/li&gt;

&lt;li&gt;Assumptions&lt;/li&gt;

&lt;li&gt;Repeated Tests&lt;/li&gt;

&lt;li&gt;

Parameterized Tests

&lt;ul&gt;
&lt;li&gt;ValueSource&lt;/li&gt;
&lt;li&gt;MethodSource&lt;/li&gt;
&lt;li&gt;CsvSource&lt;/li&gt;
&lt;li&gt;CsvFileSource&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Disabled Tests&lt;/li&gt;

&lt;li&gt;Nested Tests&lt;/li&gt;

&lt;li&gt;Running Tests using Maven Surefire Plugin&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Even though JUnit 5 is a successor for Junit 4, the architecture of the framework is completely different, so let’s have a look at the Architecture of Junit 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  Junit 5 Architecture&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The Architecture of Junit 5 can be divided into 3 different projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Junit Platform&lt;/li&gt;
&lt;li&gt;Junit Jupiter&lt;/li&gt;
&lt;li&gt;Junit Vintage&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Junit Platform&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The Junit Platform project provides an API to launch the tests from either the IDE’s, Build Tools or Console. It defines a &lt;code&gt;TestEngine&lt;/code&gt; API which enables development of new Testing Frameworks on top of the Platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Junit Jupiter&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This project provides API to write our Junit tests and extensions, it contains new annotations and a &lt;code&gt;TestEngine&lt;/code&gt; implementation to run these tests on the platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Junit Vintage&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This project provides a &lt;code&gt;TestEngine&lt;/code&gt; implementation to support backward compatibility for tests written with Junit 3 and Junit4.&lt;/p&gt;

&lt;p&gt;You can check the architecture Diagram below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2021%2F01%2Fjunit-5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2021%2F01%2Fjunit-5.png" alt="Junit 5 Architecture Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Source Code for Project under Test&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;We are going to use a Contact Manager Application while learning how to write tests using Junit 5.&lt;/p&gt;

&lt;p&gt;You can download the source code of the application from the below Github Link:&lt;br&gt;
&lt;a href="https://github.com/SaiUpadhyayula/contact-manager" rel="noopener noreferrer"&gt;https://github.com/SaiUpadhyayula/contact-manager&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Source Code for Starter Project&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;If you want to follow along this tutorial, have a look at the Starter Repository which is in the same state as the start of the tutorial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/SaiUpadhyayula/contact-manager-starter" rel="noopener noreferrer"&gt;https://github.com/SaiUpadhyayula/contact-manager-starter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Application uses Maven to manage the dependencies and build the project. If you want to learn Maven, you can check out my &lt;a href="https://programmingtechie.com/2020/12/05/complete-maven-tutorial/" rel="noopener noreferrer"&gt;Complete Maven Tutorial&lt;/a&gt; blog post. The application mainly contains 2 classes, &lt;code&gt;Contact.java&lt;/code&gt; and &lt;code&gt;ContactManager.java&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contact.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Contact {
    private String firstName;
    private String lastName;
    private String phoneNumber;

    public Contact(String firstName, String lastName, String phoneNumber) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.phoneNumber = phoneNumber;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public void validateFirstName() {
        if (this.firstName == null)
            throw new RuntimeException("First Name Cannot be null");
    }

    public void validateLastName() {
        if (this.lastName == null)
            throw new RuntimeException("Last Name Cannot be null");
    }

    public void validatePhoneNumber() {
        if (this.phoneNumber.length() != 10) {
            throw new RuntimeException("Phone Number Should be 10 Digits Long");
        }
        if (!this.phoneNumber.matches("\\d+")) {
            throw new RuntimeException("Phone Number Contain only digits");
        }
        if (!this.phoneNumber.startsWith("0")) {
            throw new RuntimeException("Phone Number Should Start with 0");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class just contains 3 necessary fields: First Name, Last Name and Phone Number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ContactManager.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContactManager {

    Map&amp;lt;String, Contact&amp;gt; contactList = new ConcurrentHashMap&amp;lt;String, Contact&amp;gt;();

    public void addContact(String firstName, String lastName, String phoneNumber) {
        Contact contact = new Contact(firstName, lastName, phoneNumber);
        validateContact(contact);
        checkIfContactAlreadyExist(contact);
        contactList.put(generateKey(contact), contact);
    }

    public Collection&amp;lt;Contact&amp;gt; getAllContacts() {
        return contactList.values();
    }

    private void checkIfContactAlreadyExist(Contact contact) {
        if (contactList.containsKey(generateKey(contact)))
            throw new RuntimeException("Contact Already Exists");
    }

    private void validateContact(Contact contact) {
        contact.validateFirstName();
        contact.validateLastName();
        contact.validatePhoneNumber();
    }

    private String generateKey(Contact contact) {
        return String.format("%s-%s", contact.getFirstName(), contact.getLastName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class contains the main business logic to maintain contact information.&lt;/p&gt;

&lt;h1&gt;
  
  
  Writing our First Test&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Now it is time to write our first Junit 5 Test.&lt;/p&gt;

&lt;p&gt;I am going to create a test class called as &lt;code&gt;ContactManagerTest.java&lt;/code&gt; under the &lt;code&gt;src/test/java&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ContactManagerTest.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class ContactManagerTest {

    @Test
    @DisplayName("Should Create Contact")
    public void shouldCreateContact() {
        ContactManager contactManager = new ContactManager();
        contactManager.addContact("John", "Doe", "0123456789");
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We created a method called &lt;code&gt;shouldCreateContact()&lt;/code&gt; which is the method testing, the contact creation.
Junit understands that this method is a Test, by looking at the &lt;code&gt;@Test&lt;/code&gt; annotation.&lt;/li&gt;
&lt;li&gt;By looking at the method name &lt;code&gt;shouldCreateContact()&lt;/code&gt; we understand what the method is trying to do, but we can also provide a custom name for this method using the &lt;code&gt;@DisplayName&lt;/code&gt; annotation.&lt;/li&gt;
&lt;li&gt;Inside the method, we created a contact by providing the first name, last name and phone number details to the &lt;code&gt;addContact()&lt;/code&gt; method of the &lt;code&gt;ContactManager&lt;/code&gt; class.&lt;/li&gt;
&lt;li&gt;We can retrieve all the contact information through the &lt;code&gt;getAllContacts()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;As a last step, we are verifying that the result of &lt;code&gt;getAllContacts()&lt;/code&gt; is not empty, and the size of the &lt;code&gt;getAllContacts()&lt;/code&gt; List is exactly 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The process of verifying the actual output with the expected output is called as performing assertions.&lt;/p&gt;

&lt;p&gt;Junit 5 provides many different methods to perform assertions for different cases.&lt;/p&gt;

&lt;p&gt;We have Assertions class which provides number of static methods, we can use in our tests.&lt;/p&gt;

&lt;p&gt;If you run the above test in IntelliJ, the test will be green. Congratulations, you wrote your first Junit 5 test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage.png" alt="Junit 5 Intellij Test Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more details about this class in the documentation - &lt;a href="https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/Assertions.html" rel="noopener noreferrer"&gt;https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/Assertions.html&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Testing Exceptions using assertThrows()&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;In our first test case, we successfully tested the Happy Path.&lt;/p&gt;

&lt;p&gt;Now let's explore some other scenarios.&lt;/p&gt;

&lt;p&gt;Here are some validations which are performed when creating a Contact:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Name should not be null&lt;/li&gt;
&lt;li&gt;Last Name should not be null&lt;/li&gt;
&lt;li&gt;Phone Number Should :&lt;/li&gt;
&lt;li&gt;Be Exactly 10 Digits Long&lt;/li&gt;
&lt;li&gt;Contain only Digits&lt;/li&gt;
&lt;li&gt;Start with 0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's write test cases to test some of the above cases, we will cover all the scenarios in the upcoming sections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ContactManagerTest.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class ContactManagerTest {

    @Test
    @DisplayName("Should Create Contact")
    public void shouldCreateContact() {
        ContactManager contactManager = new ContactManager();
        contactManager.addContact("John", "Doe", "0123456789");
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @Test
    @DisplayName("Should Not Create Contact When First Name is Null")
    public void shouldThrowRuntimeExceptionWhenFirstNameIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact(null, "Doe", "0123456789");
        });
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The 2nd Test Case, tests whether the Contact Creation is Failed when we enter the First Name as Null.&lt;/li&gt;
&lt;li&gt;We are asserting that the &lt;code&gt;addContact()&lt;/code&gt; method throws a &lt;code&gt;RuntimeException&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We can assert the Exceptions using the &lt;code&gt;assertThrow()&lt;/code&gt; method from the Assertions class&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;assertThrow()&lt;/code&gt; method takes the Exception Type as the first parameter and the Executable which is throws the Exception as the second parameter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can write similar test cases also for the fields Last Name and Phone Number like below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ContactManagerTest.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class ContactManagerTest {

    @Test
    @DisplayName("Should Create Contact")
    public void shouldCreateContact() {
        ContactManager contactManager = new ContactManager();
        contactManager.addContact("John", "Doe", "0123456789");
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @Test
    @DisplayName("Should Not Create Contact When First Name is Null")
    public void shouldThrowRuntimeExceptionWhenFirstNameIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact(null, "Doe", "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Last Name is Null")
    public void shouldThrowRuntimeExceptionWhenLastNameIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", null, "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Phone Number is Null")
    public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", "Doe", null);
        });
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can observe that I added similar test cases for the Phone Number and Last Name fields as well.&lt;/p&gt;

&lt;p&gt;You should see the below output when running the tests:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-1.png" alt="Junit5 Test Results IntelliJ"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Understanding Test Lifecycle&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Now let's go ahead and understand the Lifecycle of Junit Tests. Each Test undergoes different phases as part of it's execution, each phase is represented by an Annotation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;@BeforeAll&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method marked with this annotation will be executed before any of the &lt;code&gt;@Test&lt;/code&gt; methods are executed inside the Test class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;@BeforeEach&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method marked with this annotation will be executed before each &lt;code&gt;@Test&lt;/code&gt; method in the Test class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;@AfterEach&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method marked with this annotation will be executed after each &lt;code&gt;@Test&lt;/code&gt; method in the Test class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;@AfterAll&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method marked with this annotation will be executed after all the &lt;code&gt;@Test&lt;/code&gt; methods are executed in the Test class.&lt;/p&gt;

&lt;p&gt;The Before methods (&lt;strong&gt;@BeforeAll&lt;/strong&gt;, &lt;strong&gt;@BeforeEach&lt;/strong&gt;) perform some initialization actions like setting up of test data or environment data, before executing the tests.&lt;/p&gt;

&lt;p&gt;The After methods (&lt;strong&gt;@AfterAl&lt;/strong&gt;l, &lt;strong&gt;@AfterEach&lt;/strong&gt;) perform clean up actions like cleaning up of created Environment Data or Test Data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@BeforeAll&lt;/strong&gt; and &lt;strong&gt;@AfterAll&lt;/strong&gt; are called only once for the entire test, and the methods are usually marked as &lt;strong&gt;static&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fjunit5_test_lifecycle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fjunit5_test_lifecycle.png" alt="Junit 5 Test Lifecycle"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing Lifecycle Annotations in our Test&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;So now, let’s see how we can use the above mentioned Lifecycle annotations, in our test.&lt;/p&gt;

&lt;p&gt;In our 4 tests, we can observe that we are creating an instance of &lt;strong&gt;ContactManager&lt;/strong&gt; at the start of each test.&lt;/p&gt;

&lt;p&gt;This logic can go inside the method which is marked with either &lt;strong&gt;@BeforeAll&lt;/strong&gt; or &lt;strong&gt;@BeforeEach&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  @BeforeAll and @AfterAll&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class ContactManagerTest {

    private static ContactManager contactManager;

    @BeforeAll
    public static void setup() {
        System.out.println("Instantiating Contact Manager before the Test Execution");
        contactManager = new ContactManager();
    }

    @Test
    @DisplayName("Should Create Contact")
    public void shouldCreateContact() {
        contactManager.addContact("John", "Doe", "0123456789");
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @Test
    @DisplayName("Should Not Create Contact When First Name is Null")
    public void shouldThrowRuntimeExceptionWhenFirstNameIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact(null, "Doe", "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Last Name is Null")
    public void shouldThrowRuntimeExceptionWhenLastNameIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", null, "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Phone Number is Null")
    public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull() {
        ContactManager contactManager = new ContactManager();
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", "Doe", null);
        });
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I created a method called as &lt;code&gt;setup()&lt;/code&gt; which is marked with &lt;code&gt;@BeforeAll&lt;/code&gt; annotation, inside this method, I instantiated the &lt;strong&gt;ContactManager&lt;/strong&gt; and assigned the object to the &lt;code&gt;static&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;I also added a method called as &lt;code&gt;tearDown()&lt;/code&gt; which is marked with &lt;code&gt;@AfterAll&lt;/code&gt; annotation, we expect this method to be executed at the end of the test.&lt;/p&gt;

&lt;p&gt;If you run the tests again, you should see the output like you see in the below image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-2.png%3Fresize%3D1536%252C450%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-2.png%3Fresize%3D1536%252C450%26ssl%3D1" alt="Test Execution With BeforeAll and AfterAll"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  @BeforeEach and @AfterEach&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;By using this annotation, we can perform some operations which needs to be done Before and After Each Test Execution.&lt;/p&gt;

&lt;p&gt;Note that, Junit always creates a new instance of the test before executing each &lt;code&gt;@Test&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class ContactManagerTest {

    private ContactManager contactManager;

    @BeforeAll
    public static void setupAll() {
        System.out.println("Should Print Before All Tests");
    }

    @BeforeEach
    public void setup() {
        System.out.println("Instantiating Contact Manager");
        contactManager = new ContactManager();
    }

    @Test
    @DisplayName("Should Create Contact")
    public void shouldCreateContact() {
        contactManager.addContact("John", "Doe", "0123456789");
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @Test
    @DisplayName("Should Not Create Contact When First Name is Null")
    public void shouldThrowRuntimeExceptionWhenFirstNameIsNull() {
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact(null, "Doe", "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Last Name is Null")
    public void shouldThrowRuntimeExceptionWhenLastNameIsNull() {
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", null, "0123456789");
        });
    }

    @Test
    @DisplayName("Should Not Create Contact When Phone Number is Null")
    public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull() {
        Assertions.assertThrows(RuntimeException.class, () -&amp;gt; {
            contactManager.addContact("John", "Doe", null);
        });
    }

    @AfterEach
    public void tearDown() {
        System.out.println("Should Execute After Each Test");
    }

    @AfterAll
    public static void tearDownAll() {
        System.out.println("Should be executed at the end of the Test");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I moved the logic to create the &lt;code&gt;ContactManager&lt;/code&gt; object inside the &lt;code&gt;setup()&lt;/code&gt; method marked with &lt;code&gt;@BeforeEach&lt;/code&gt; and I renamed the method marked with &lt;code&gt;@BeforeAll&lt;/code&gt; to &lt;code&gt;setupAll()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I also introduced a new method called as &lt;code&gt;tearDown()&lt;/code&gt; which is just logging some random text, just to show you that the method is executing after each test execution.&lt;/p&gt;

&lt;p&gt;If you run the above test, this is how the output should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-3.png%3Fresize%3D1536%252C658%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-3.png%3Fresize%3D1536%252C658%26ssl%3D1" alt="Test Execution Junit 5 BeforeEach and AfterEach"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Default Test Instance Lifecycle&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;As mentioned above, Junit instantiates the Test class for each method marked with &lt;code&gt;@Test&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For this reason, the method marked with &lt;code&gt;@BeforeAll&lt;/code&gt; and &lt;code&gt;@AfterAll&lt;/code&gt; should be marked with &lt;code&gt;static&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing Default Test Instance Lifecycle&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can change this default behavior, by instructing Junit to create an instance of the Test class, only once using the below annotation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@TestInstance(Lifecylce.PER_CLASS)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By using the above annotation, there is no need to mark the &lt;code&gt;@BeforeAll&lt;/code&gt; and &lt;code&gt;@AfterAll&lt;/code&gt; methods as &lt;code&gt;static&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conditional Executions&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;We can execute the &lt;code&gt;@Test&lt;/code&gt; methods in our class based on a specific condition, for example: imagine if you developed a specific functionality on Linux for our Contact Manager application. After saving the contact, we are performing some additional logic which is specific to Linux Operating System.&lt;/p&gt;

&lt;p&gt;Then we have to make sure that the test should only run when it’s running only on Linux Operating System.&lt;/p&gt;

&lt;p&gt;You can enable this conditional execution using different annotations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@EnabledOnOs&lt;/li&gt;
&lt;li&gt;@DisabledOnOs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These annotations take the values for usual Operating Systems like &lt;strong&gt;MAC&lt;/strong&gt;, &lt;strong&gt;LINUX&lt;/strong&gt;, &lt;strong&gt;WINDOWS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can see the example usage of this annotation below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
@DisplayName("Should Create Contact")
@EnabledOnOs(value = OS.MAC, disabledReason = "Should Run only on MAC")
public void shouldCreateContact() {
    contactManager.addContact("John", "Doe", "0123456789");
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also provide a reason using the disabledReason field, you can see the output in the below image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-4.png%3Fresize%3D1536%252C731%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-4.png%3Fresize%3D1536%252C731%26ssl%3D1" alt="Junit 5 Disabled Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Assumptions&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;We can also perform conditional Assertions using Junit 5 &lt;strong&gt;Assumptions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There may be particular test cases you want to make sure that you are running based on certain conditions.&lt;/p&gt;

&lt;p&gt;You can have some test cases which should be executed only on Developer Machine but not on CI environment.&lt;/p&gt;

&lt;p&gt;Or you can also have some slow running tests, you can enable on disable them based on certain conditions.&lt;/p&gt;

&lt;p&gt;You can perform this assumptions in Junit 5 similar to the Assertions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
@DisplayName("Test Contact Creation on Developer Machine")
public void shouldTestContactCreationOnDEV() {
    Assumptions.assumeTrue("DEV".equals(System.getProperty("ENV")));
    contactManager.addContact("John", "Doe", "0123456789");
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above test, you can see that we are using the Assumptions.assumeTrue() method to execute the tests, only when the ENV System Property is equal to DEV.&lt;/li&gt;
&lt;li&gt;If the above assumption failed, then the test will not be executed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the output when the assumptions is failed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-5.png%3Fresize%3D1536%252C397%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-5.png%3Fresize%3D1536%252C397%26ssl%3D1" alt="Assumptions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s go ahead and add the System Property &lt;strong&gt;ENV&lt;/strong&gt; to the VM Options of the &lt;code&gt;ContactManagerTest&lt;/code&gt; class, you can do that by clicking on the &lt;strong&gt;Edit Configuration&lt;/strong&gt; options for the Test inside IntelliJ.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-6.png%3Fw%3D1008%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-6.png%3Fw%3D1008%26ssl%3D1" alt="Edit Configuration for Test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you run the test after activating this property, you can see that the test is executed successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-7.png%3Fw%3D1153%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-7.png%3Fw%3D1153%26ssl%3D1" alt="Test Result for Assumptions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Repeated Tests&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;If you have any functionality which has some randomness to it, you may want to create and run that test multiple times, to make sure that the functionality is working as expected.&lt;/p&gt;

&lt;p&gt;Junit 5 provides us the &lt;code&gt;@RepeatedTest&lt;/code&gt; annotation to fulfil this requirement.&lt;/p&gt;

&lt;p&gt;You can repeat the Test N number of time by passing the number as an argument to the annotation.Eg: &lt;code&gt;@RepeatedTest(5)&lt;/code&gt; will run the test marked with this annotation 5 times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("Repeat Contact Creation Test 5 Times")
@RepeatedTest(5)
public void shouldTestContactCreationRepeatedly() {
    contactManager.addContact("John", "Doe", "0123456789");
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the above test, you can see the below output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-8.png%3Fw%3D1170%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-8.png%3Fw%3D1170%26ssl%3D1" alt="Repeated Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can create that IntelliJ displays an expandable node where you can see the output for each repetition.&lt;/p&gt;

&lt;p&gt;You can also specify custom names instead of the default repetition 1 of 5, using the name field.&lt;/p&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;code&gt;@RepeatedTest(value = 5,&lt;br&gt;
        name = "Repeating Contact Creation Test {currentRepetition} of {totalRepetitions}")&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("Repeat Contact Creation Test 5 Times")
@RepeatedTest(value = 5,
        name = "Repeating Contact Creation Test {currentRepetition} of {totalRepetitions}")
public void shouldTestContactCreationRepeatedly() {
    contactManager.addContact("John", "Doe", "0123456789");
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run the above test, you can see the below output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-9.png%3Fw%3D790%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-9.png%3Fw%3D790%26ssl%3D1" alt="Junit 5 Repeating Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Parameterized Tests&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;You can also run parametrized tests by running a test multiple times and providing different set of inputs for each repetition.&lt;/p&gt;

&lt;p&gt;We have to add the &lt;code&gt;@ParameterizedTest&lt;/code&gt; annotation to mark a test method as Parameterized Test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
@DisplayName("Phone Number should start with 0")
public void shouldTestPhoneNumberFormat() {
    contactManager.addContact("John", "Doe", "0123456789");
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above testcase, we are checking whether the provided phone number is in the required format or not. i.e.. If the Phone Number is starting with 0&lt;/p&gt;

&lt;p&gt;We can run this test against different set’s of input and make sure that the test is working as expected or not.&lt;/p&gt;

&lt;p&gt;You can provide the input to the test using different ways:&lt;/p&gt;

&lt;h2&gt;
  
  
  ValueSource&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can provide input to the Parameterized Test using the &lt;code&gt;@ValueSource&lt;/code&gt; annotation where you can provide a set of &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt; literals to our test.&lt;/p&gt;

&lt;p&gt;Eg: &lt;code&gt;@ValueSource(strings = {“string1″,”string2″,”string3”})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you can access this string inside the test by first adding a String parameter to our test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("Phone Number should match the required Format")
@ParameterizedTest
@ValueSource(strings = {"0123456789", "1234567890", "+0123456789"})
public void shouldTestPhoneNumberFormat(String phoneNumber) {
    contactManager.addContact("John", "Doe", phoneNumber);
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we are providing the Phone Number String in different formats.&lt;/p&gt;

&lt;p&gt;If you run the above test, it provides the below output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-9.png%3Fw%3D790%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-9.png%3Fw%3D790%26ssl%3D1" alt="Value Source"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Test verifies whether the Phone Number starts with 0 or not, as we provided invalid inputs for the 2nd and 3rd cases, the tests failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  MethodSource&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We can also use &lt;code&gt;@MethodSource&lt;/code&gt; annotation to provide the input to our Parameterized Tests, using this annotation we will refer the method name which returns the values required for our tests as output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("Method Source Case - Phone Number should match the required Format")
@ParameterizedTest
@MethodSource("phoneNumberList")
public void shouldTestPhoneNumberFormatUsingMethodSource(String phoneNumber) {
    contactManager.addContact("John", "Doe", phoneNumber);
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}

private List&amp;lt;String&amp;gt; phoneNumberList() {
    return Arrays.asList("0123456789", "1234567890", "+0123456789");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above test, we declared a method called as &lt;code&gt;phoneNumberList()&lt;/code&gt; which returns the required input values as a &lt;code&gt;List&amp;lt;String&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We passed the name of this method as the value to the &lt;code&gt;@MethodSource&lt;/code&gt; annotation.&lt;/p&gt;

&lt;p&gt;You can see the below output when you run the test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-10.png%3Fw%3D789%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-10.png%3Fw%3D789%26ssl%3D1" alt="Method Source"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CsvSource&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can create an inline CSV which contains the input for the test and reference that using the &lt;code&gt;@CsvSource&lt;/code&gt; annotation.&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;code&gt;@CsvSource({"1,0123456789", "2,1234567890","3,+0123456789"})&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("CSV Source Case - Phone Number should match the required Format")
@ParameterizedTest
@CsvSource({"0123456789", "1234567890","+0123456789"})
public void shouldTestPhoneNumberFormatUsingCSVSource(String phoneNumber) {
    contactManager.addContact("John", "Doe", phoneNumber);
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CsvFileSource&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can also reference a CSV File by using the &lt;code&gt;@CsvFileSource&lt;/code&gt;annotation.&lt;/p&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;code&gt;@CsvFileSource(resources = "/data.csv")&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@DisplayName("CSV File Source Case - Phone Number should match the required Format")
@ParameterizedTest
@CsvFileSource(resources = "/data.csv")
public void shouldTestPhoneNumberFormatUsingCSVFileSource(String phoneNumber) {
    contactManager.addContact("John", "Doe", phoneNumber);
    assertFalse(contactManager.getAllContacts().isEmpty());
    assertEquals(1, contactManager.getAllContacts().size());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The contents of the csv looks like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0123456789
1234567890
+0123456789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how the expected output looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-12.png%3Fw%3D838%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-12.png%3Fw%3D838%26ssl%3D1" alt="CSV File Source"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Disabled Tests&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;You can disable some tests from running by adding the @Disabled annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
@DisplayName("Test Should Be Disabled")
@Disabled
public void shouldBeDisabled() {
    throw new RuntimeException("Test Should Not be executed");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the above test, you can see the output from Junit 5 that the test &lt;code&gt;shouldBeDisabled()&lt;/code&gt; is &lt;code&gt;@Disabled&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-13.png%3Fresize%3D1536%252C458%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-13.png%3Fresize%3D1536%252C458%26ssl%3D1" alt="Disabled Test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Nested Tests&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;By now, you may have observed that our &lt;code&gt;ContactManagerTest&lt;/code&gt; contains lots of test methods, we can organize these tests into Nested Tests using the &lt;code&gt;@Nested&lt;/code&gt; annotation.&lt;/p&gt;

&lt;p&gt;We are going to take a group of Tests and organize them into a seperate category of tests by creating a class and adding the &lt;code&gt;@Nested&lt;/code&gt; annotation to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Nested
class ParameterizedTests {
    @DisplayName("Phone Number should match the required Format")
    @ParameterizedTest
    @ValueSource(strings = {"0123456789", "1234567890", "+0123456789"})
    public void shouldTestPhoneNumberFormatUsingValueSource(String phoneNumber) {
        contactManager.addContact("John", "Doe", phoneNumber);
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @DisplayName("CSV Source Case - Phone Number should match the required Format")
    @ParameterizedTest
    @CsvSource({"0123456789", "1234567890", "+0123456789"})
    public void shouldTestPhoneNumberFormatUsingCSVSource(String phoneNumber) {
        contactManager.addContact("John", "Doe", phoneNumber);
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }

    @DisplayName("CSV File Source Case - Phone Number should match the required Format")
    @ParameterizedTest
    @CsvFileSource(resources = "/data.csv")
    public void shouldTestPhoneNumberFormatUsingCSVFileSource(String phoneNumber) {
        contactManager.addContact("John", "Doe", phoneNumber);
        assertFalse(contactManager.getAllContacts().isEmpty());
        assertEquals(1, contactManager.getAllContacts().size());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, you can see that we grouped all the Parameterized Tests together into a separate class.&lt;/p&gt;

&lt;p&gt;If I run the tests you will see that the parameterized tests are displayed under a different node.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-14.png%3Fw%3D1175%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fimage-14.png%3Fw%3D1175%26ssl%3D1" alt="Nested Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Running Tests using Maven Surefire Plugin&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Usually, you will run the tests when building the application, on a CI server. Maven is a build tool which helps us in automating the manual tasks associated with building the project.&lt;/p&gt;

&lt;p&gt;We can use the &lt;a href="https://programmingtechie.com/2020/12/05/complete-maven-tutorial/#Maven_Surefire_Plugin" rel="noopener noreferrer"&gt;Maven Surefire Plugin&lt;/a&gt; to execute the tests as part of the build, all you have to do is configure the plugin in the pom.xml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;plugin&amp;gt;
    &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;2.22.2&amp;lt;/version&amp;gt;
&amp;lt;/plugin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should also add the &lt;a href="https://programmingtechie.com/2020/12/05/complete-maven-tutorial/#Maven_Compile_Plugin" rel="noopener noreferrer"&gt;Maven Compiler Plugin&lt;/a&gt; to compile our test classes as part of the build.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;plugin&amp;gt;
    &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
    &amp;lt;configuration&amp;gt;
        &amp;lt;!--Use this only when using Java 9+--&amp;gt;
        &amp;lt;release&amp;gt;15&amp;lt;/release&amp;gt;
        &amp;lt;!--
        Uncomment this and comment out &amp;lt;release&amp;gt; when using Java 8
        &amp;lt;source&amp;gt;1.8&amp;lt;/source&amp;gt;
        &amp;lt;target&amp;gt;1.8&amp;lt;/target&amp;gt;
        --&amp;gt;
    &amp;lt;/configuration&amp;gt;
&amp;lt;/plugin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;configuration&lt;/strong&gt; section compiles the test classes according to the target JDK version.&lt;/p&gt;

&lt;p&gt;If you are using Java 9+ you should just use the &lt;strong&gt;release&lt;/strong&gt; tag and if you are using Java 8, then you should uncomment the &lt;strong&gt;source&lt;/strong&gt; and &lt;strong&gt;target&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;After adding these plugins, you can run the tests using the command &lt;code&gt;mvn clean test&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;λ mvn clean test
 [INFO] Scanning for projects…
 [INFO]
 [INFO] --------------------&amp;lt; org.example:contact-manager &amp;gt;---------------------
 [INFO] Building contact-manager 1.0-SNAPSHOT
 [INFO] --------------------------------[ jar ]---------------------------------
 [INFO]
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ contact-manager ---
 [INFO] Deleting F:\contact-manager\target
 [INFO]
 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ contact-manager ---
 [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
 [INFO] Copying 0 resource
 [INFO]
 [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ contact-manager ---
 [INFO] Changes detected - recompiling the module!
 [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
 [INFO] Compiling 2 source files to F:\contact-manager\target\classes
 [INFO]
 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ contact-manager ---
 [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
 [INFO] Copying 1 resource
 [INFO]
 [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ contact-manager ---
 [INFO] Changes detected - recompiling the module!
 [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
 [INFO] Compiling 1 source file to F:\contact-manager\target\test-classes
 [INFO]
 [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ contact-manager ---
 [INFO]
 [INFO] -------------------------------------------------------
 [INFO]  T E S T S
 [INFO] -------------------------------------------------------
 [INFO] Running ContactManagerTest
 Should Print Before All Tests
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Instantiating Contact Manager
 Should Execute After Each Test
 Should be executed at the end of the Test
 [WARNING] Tests run: 24, Failures: 0, Errors: 0, Skipped: 3, Time elapsed: 0.215 s - in ContactManagerTest
 [INFO]
 [INFO] Results:
 [INFO]
 [WARNING] Tests run: 24, Failures: 0, Errors: 0, Skipped: 3
 [INFO]
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time:  2.813 s
 [INFO] Finished at: 2020-12-26T00:41:57+01:00
 [INFO] ------------------------------------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;So we reached to the end of the Junit 5 Complete Tutorial, I hope you learned something about Junit 5.&lt;/p&gt;

&lt;p&gt;Please don’t forget to share this article with your friends and colleagues if they find it useful.&lt;/p&gt;

&lt;p&gt;I will see you in the next article, until then Happy Coding Techies 🙂&lt;/p&gt;

</description>
      <category>java</category>
      <category>junit5</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Maven Complete Tutorial for Beginners</title>
      <dc:creator>Sai Upadhyayula</dc:creator>
      <pubDate>Sat, 19 Dec 2020 21:58:11 +0000</pubDate>
      <link>https://dev.to/saiupadhyayula/maven-complete-tutorial-for-beginners-1jek</link>
      <guid>https://dev.to/saiupadhyayula/maven-complete-tutorial-for-beginners-1jek</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post was originally published in &lt;a href="https://programmingtechie.com/" rel="noopener noreferrer"&gt;programmingtechie.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are a Java Developer, your day to day activities while working on Java Projects includes writing code, compiling code, testing, packaging code in the form of an artifact like JAR, WAR or EAR and then deploying this artifact to an Application Server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Apache Maven&lt;/strong&gt; automates all the tasks which are mentioned above by minimizing the manual overhead.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will understand &lt;strong&gt;What is Apache Maven?&lt;/strong&gt; and will cover all the concepts required for you to start using Maven in your Java Projects&lt;/p&gt;

&lt;p&gt;If you are a visual learner like me, check out the below video tutorial:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/JhSBS2OpGdU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is Apache Maven&lt;/li&gt;
&lt;li&gt;Installing Maven&lt;/li&gt;
&lt;li&gt;Configure Maven Installation in IDE&lt;/li&gt;
&lt;li&gt;Create your First Maven Project&lt;/li&gt;
&lt;li&gt;Exploring Maven Folder Structure&lt;/li&gt;
&lt;li&gt;
Maven Core Concepts

&lt;ul&gt;
&lt;li&gt;
Project Object Model

&lt;ul&gt;
&lt;li&gt;Simple POM File&lt;/li&gt;
&lt;li&gt;Super POM File&lt;/li&gt;
&lt;li&gt;Effective POM File&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Dependencies

&lt;ul&gt;
&lt;li&gt;Transitive Dependencies&lt;/li&gt;
&lt;li&gt;Excluding Dependencies&lt;/li&gt;
&lt;li&gt;SNAPSHOT and RELEASE dependencies&lt;/li&gt;
&lt;li&gt;Dependency Scopes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Repositories

&lt;ul&gt;
&lt;li&gt;Snapshot and Release Version Handling&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;Maven Build Lifecycle&lt;/li&gt;

&lt;li&gt;

Plugins and Goals

&lt;ul&gt;
&lt;li&gt;Maven Compile Plugin&lt;/li&gt;
&lt;li&gt;Maven Surefire Plugin&lt;/li&gt;
&lt;li&gt;Maven Install Plugin&lt;/li&gt;
&lt;li&gt;Maven Deploy Plugin&lt;/li&gt;
&lt;li&gt;Other Maven Plugins&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Maven Multi Module Projects

&lt;ul&gt;
&lt;li&gt;Creating Multi Module Project using IntelliJ&lt;/li&gt;
&lt;li&gt;Managing Dependencies inside Maven Multi Module Project&lt;/li&gt;
&lt;li&gt;Managing Plugins inside Maven Multi Module Project&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Using Profiles&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is Apache Maven ?&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Apache Maven&lt;/strong&gt; is a Project Management Tool used to manage projects which are developed using JVM languages like Java, Scala, Groovy etc.&lt;/p&gt;

&lt;p&gt;The major tasks of a Project Management Tool include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building the Source Code&lt;/li&gt;
&lt;li&gt;Testing Source Code&lt;/li&gt;
&lt;li&gt;Packaging the Source Code into an Artifact (ZIP, JAR, WAR or EAR)&lt;/li&gt;
&lt;li&gt;Handles Versioning and Releases of the Artifacts&lt;/li&gt;
&lt;li&gt;Generating JavaDocs from the Source Code&lt;/li&gt;
&lt;li&gt;Managing Project Dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Maven is also called as a &lt;strong&gt;Build Tool&lt;/strong&gt; or a &lt;strong&gt;Dependency Management Tool&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Installing Maven&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;You can download Maven from the website &lt;a href="https://maven.apache.org/download.cgi?Preferred=ftp://ftp.osuosl.org/pub/apache/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. At the time of writing this tutorial, the latest version of Maven is 3.6.3.&lt;/p&gt;

&lt;p&gt;Under the Files section, you can download Maven by clicking on the link which looks something like &lt;a href="https://mirrors.supportex.net/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip" rel="noopener noreferrer"&gt;apache-maven-3.6.3-bin.zip&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have downloaded and unzipped the folder, make sure to add the M2_HOME environment variable and to set the value of this variable to location of the unzipped folder.&lt;/p&gt;

&lt;p&gt;After that make sure to set another environment variable called M2 which contains the value M2_HOME/bin&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven_Env_Variables.png%3Fw%3D626%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven_Env_Variables.png%3Fw%3D626%26ssl%3D1" alt="M2 Environment Variable"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, make sure to update the Path variable also with the M2 environment variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven_Env_Variable_Path.png%3Fw%3D527%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven_Env_Variable_Path.png%3Fw%3D527%26ssl%3D1" alt="M2 Environment Variable inside Path"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you completed the above steps, open a new terminal window and type &lt;code&gt;mvn –version&lt;/code&gt; and you should see the output like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Version-Check.png%3Fw%3D1245%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Version-Check.png%3Fw%3D1245%26ssl%3D1" alt="Maven Version Check"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure Maven Installation in IDE&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;The next step is to configure the maven installation inside your favorite IDE, in this tutorial we are going to use IntelliJ IDEA as the primary IDE.&lt;/p&gt;

&lt;p&gt;You can download the community edition of this IDE &lt;a href="https://www.jetbrains.com/idea/download/#section=windows" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have installed the IDE, on the Welcome Window click on the &lt;strong&gt;Configure&lt;/strong&gt; button and select Settings and inside the Settings Window search for Maven and under the &lt;strong&gt;Maven home directory&lt;/strong&gt; choose the Maven directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fconfigure-maven-1.png%3Fw%3D802%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fconfigure-maven-1.png%3Fw%3D802%26ssl%3D1" alt="IntelliJ"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fconfigure-maven-2.png%3Fw%3D982%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2Fconfigure-maven-2.png%3Fw%3D982%26ssl%3D1" alt="Configure Maven"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;Apply&lt;/strong&gt; and then &lt;strong&gt;OK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You configured Maven successfully in your IDE. Now it’s time to create our first Maven Project.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create your First Maven Project&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;In IntelliJ, click on &lt;strong&gt;New Project&lt;/strong&gt; and in the window, select &lt;strong&gt;Maven&lt;/strong&gt; to the left side and click on &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then enter your project name and if you expand the section &lt;strong&gt;Artifact Coordinates&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You will see the fields &lt;strong&gt;GroupId&lt;/strong&gt;, &lt;strong&gt;ArtifactId&lt;/strong&gt; and &lt;strong&gt;Version&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A GroupId is like a identifier for your project which usually follows the Java Package naming convention, so in our example IntelliJ has by default added the value org.example but you can add any value you like.&lt;/li&gt;
&lt;li&gt;An ArtifactId is the name of the project you are creating&lt;/li&gt;
&lt;li&gt;A Version is a unique number which identifies the version of our project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FNew-Project.png%3Fw%3D1204%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FNew-Project.png%3Fw%3D1204%26ssl%3D1" alt="Artifact Coordinates"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you click on &lt;strong&gt;Finish&lt;/strong&gt;, IntelliJ should open the project and the folder structure of the project will look something like the picture you see below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Project-Structure.png%3Fw%3D922%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Project-Structure.png%3Fw%3D922%26ssl%3D1" alt="Maven Project Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Exploring Maven Folder Structure&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Let’s have a look at the Folder Structure of the Maven Project we just created.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;src&lt;/strong&gt; folder is the root for our application source code and tests. Then we have the following subfolders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The folder &lt;strong&gt;src/main/java&lt;/strong&gt; contains the java source code, all the production code for our application resides here&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;src/main/resources&lt;/strong&gt; we will store all the files we are going to use in our project (example: Property Files, any files where we need to read in our application like XML, CSV etc.). If you are developing a web-application we will usually place all the static resources inside this folder.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;src/test/java&lt;/strong&gt; folder we will store all the test classes in our project.&lt;/li&gt;
&lt;li&gt;There is another folder called &lt;strong&gt;target&lt;/strong&gt; (currently not visible), which stores the compiled java class files. We will discuss about this in the coming sections&lt;/li&gt;
&lt;li&gt;And lastly, we have the &lt;strong&gt;pom.xml&lt;/strong&gt; file which contains the metadata of the project dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Maven Core Concepts&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Project Object Model&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Project Object Model&lt;/strong&gt; File(also called as &lt;strong&gt;pom.xml&lt;/strong&gt;) contains the meta-data of the project and is also responsible to manage dependencies and to configure plugins which helps us in automating many repetitive tasks.&lt;/p&gt;

&lt;p&gt;Here is how a basic &lt;strong&gt;pom.xml&lt;/strong&gt; file looks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;  
&amp;lt;/project&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;project&lt;/strong&gt; is the top level tag of our &lt;strong&gt;pom.xml&lt;/strong&gt; file, which encapsulates all the information related to our Maven Project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;modelVersion&lt;/strong&gt; represents what version of POM you are using. The modelVersion for Maven 3 is always 4.0. This will never change unless you are using another major version of Maven.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now as we know what is a POM file, let’s have a look at different type’s of POM files. We have basically 3 types of POM files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple POM file&lt;/li&gt;
&lt;li&gt;Super POM file&lt;/li&gt;
&lt;li&gt;Effective POM file&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Simple POM File&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This is the same file(&lt;strong&gt;pom.xml&lt;/strong&gt;) which was generated in the previous section. It only contains information which is relevant to our current project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Super POM File&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Super POM File&lt;/strong&gt; is a parent for all the &lt;strong&gt;Simple POM files&lt;/strong&gt;, it contains a set of default configuration which is shared by all the &lt;strong&gt;Simple POM&lt;/strong&gt; files.&lt;/p&gt;

&lt;p&gt;You can find the &lt;strong&gt;Super POM&lt;/strong&gt; file inside the Maven installation directory under the path &lt;strong&gt;M2_HOME/lib&lt;/strong&gt; and inside the JAR file &lt;strong&gt;maven-model-builder-XXX.jar&lt;/strong&gt; where XXX represents the version of the maven version you are using.&lt;/p&gt;

&lt;p&gt;We can find it under the package name &lt;strong&gt;org.apache.maven.model&lt;/strong&gt; under the file name &lt;strong&gt;pom-4.0.0.xml&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;CAUTION&lt;/strong&gt;: You should never try to edit the Super POM as it contains sensible defaults from Maven.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Effective POM File&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;Effective POM File&lt;/strong&gt; is nothing but a combination of &lt;strong&gt;Simple POM&lt;/strong&gt; and &lt;strong&gt;Super POM&lt;/strong&gt; File’s.&lt;/p&gt;

&lt;p&gt;It’s just a way of checking all the information of the pom.xml files in one place.&lt;/p&gt;

&lt;p&gt;We will have a look at how this will be helpful in the upcoming sections.&lt;/p&gt;

&lt;p&gt;You can have a look at the &lt;strong&gt;Effective POM&lt;/strong&gt; of our &lt;strong&gt;pom.xml&lt;/strong&gt; file by typing the following command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mvn help:effective-pom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In IntelliJ, you can simply right click on the &lt;strong&gt;pom.xml&lt;/strong&gt; file, select &lt;strong&gt;Maven&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Show Effective POM&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;If you are working on any non-trivial Java Project chances are that you are using many third party JAR files in your project to develop the application. These JAR files can be anything like a Framework or a Library. Examples include &lt;strong&gt;Junit&lt;/strong&gt;, &lt;strong&gt;Spring Framework&lt;/strong&gt;, &lt;strong&gt;Selenium&lt;/strong&gt; etc.&lt;/p&gt;

&lt;p&gt;These external libraries are called as &lt;strong&gt;dependencies&lt;/strong&gt;. Maven provides an excellent way to specify and manage dependencies in our &lt;strong&gt;pom.xml&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Without using Maven, you have to manually download the required JAR files from internet and add them one-by-one to the classpath of our project.&lt;/p&gt;

&lt;p&gt;Maven provides a &lt;strong&gt;dependencies&lt;/strong&gt; section inside the pom.xml where you can specify the information of the JAR you require in your project (&lt;strong&gt;groupId&lt;/strong&gt;, &lt;strong&gt;artifactId&lt;/strong&gt; and &lt;strong&gt;version&lt;/strong&gt;). Once you have specified the required libraries, maven will automatically download these dependencies into our project and adds them to the classpath of our project.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;dependencies&lt;/strong&gt; section you can define each individual dependency like below inside the &lt;strong&gt;pom.xml&lt;/strong&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;

    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.junit.jupiter&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;junit-jupiter-engine&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;5.5.2&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;
&amp;lt;/project&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We have defined &lt;strong&gt;Junit5&lt;/strong&gt; as a &lt;strong&gt;dependency&lt;/strong&gt; in our &lt;strong&gt;pom.xml&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Notice that I have mentioned the tags &lt;strong&gt;groupId&lt;/strong&gt;, &lt;strong&gt;artifactId&lt;/strong&gt; and &lt;strong&gt;version&lt;/strong&gt; to uniquely identify a dependency and by providing these values, Maven can automatically download these dependencies to our project.&lt;/p&gt;

&lt;p&gt;In IntelliJ, make sure to click on the Refresh button under the Maven Tab in the right side, to force IntelliJ to initiate the download of the dependencies. Check the below image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Dependencies-1.png%3Fresize%3D1536%252C725%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMaven-Dependencies-1.png%3Fresize%3D1536%252C725%26ssl%3D1" alt="Intellij Maven Dependencies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this way, you can provide all the dependencies needed in your project inside the pom.xml and Maven will automatically download them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transitive Dependencies&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In the above example, you can observe that the &lt;strong&gt;junit-jupiter-engine&lt;/strong&gt; indeed depends on other JAR files like &lt;strong&gt;apiguardian-api&lt;/strong&gt;, &lt;strong&gt;junit-platform-engine&lt;/strong&gt; and &lt;strong&gt;junit-jupiter-api&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These JAR files are called &lt;strong&gt;Transitive Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMavne-Dependencies-1.png%3Fw%3D1229%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FMavne-Dependencies-1.png%3Fw%3D1229%26ssl%3D1" alt="Maven Transitive Dependencies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Excluding Dependencies&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;There are some instances where we will have some conflicts between the project dependencies and the transitive dependencies, at that time we can manually exclude the transitive dependency we don’t need.&lt;/p&gt;

&lt;p&gt;For example, if you are developing your application using Spring Boot, there is a dependency called &lt;strong&gt;spring-boot-starter-test&lt;/strong&gt; which will provide all the dependencies needed to test the Spring Boot applications.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;spring-boot-starter-test&lt;/strong&gt; dependency contains &lt;strong&gt;Junit 4&lt;/strong&gt; as the transitive dependency, as we are already using &lt;strong&gt;Junit 5&lt;/strong&gt; we can exclude the transitive dependency like below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;

    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.junit.jupiter&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;junit-jupiter-engine&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;5.5.2&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-test&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.1.6.RELEASE&amp;lt;/version&amp;gt;
            &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
            &amp;lt;exclusions&amp;gt;
                &amp;lt;exclusion&amp;gt;
                    &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
                    &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
                &amp;lt;/exclusion&amp;gt;
            &amp;lt;/exclusions&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;
&amp;lt;/project&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: The newer Spring Boot versions comes with JUnit 5 dependency, I purposely used the old version &lt;strong&gt;2.1.6.RELEASE&lt;/strong&gt; as an example.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  SNAPSHOT and RELEASE dependencies&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A dependency can be categorized into two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SNAPSHOT&lt;/li&gt;
&lt;li&gt;RELEASE
A Snapshot Dependency resembles that the project version is under development.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are working on a Java project in a team, chances are that you are following some kind of iterative process where you go through the phases of development and then release the software at the end of the phase.&lt;/p&gt;

&lt;p&gt;When the project is under development we generally use the &lt;strong&gt;SNAPSHOT&lt;/strong&gt; dependencies, which looks something like &lt;strong&gt;1.0-SNAPSHOT&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
&amp;lt;/project&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When the software is ready for release, we generally create a RELEASE version which looks like &lt;strong&gt;1.0.RELEASE&lt;/strong&gt; (ex: &lt;strong&gt;Spring Boot Starter Test dependency&lt;/strong&gt;)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-boot-starter-test&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;2.1.6.RELEASE&amp;lt;/version&amp;gt;
    &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
    &amp;lt;exclusions&amp;gt;
        &amp;lt;exclusion&amp;gt;
            &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
        &amp;lt;/exclusion&amp;gt;
    &amp;lt;/exclusions&amp;gt;
&amp;lt;/dependency&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Dependency Scopes&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Each Maven Dependency can be categorized 6 different scopes.&lt;/p&gt;

&lt;p&gt;Here are the list of scopes available:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;compile&lt;/strong&gt;: This is the default scope if none is specified. Compile time dependencies are available in classpath of the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;provided&lt;/strong&gt;: Similar to &lt;strong&gt;compile&lt;/strong&gt; scope, but indicates that the JDK or the underlying container will provide the dependency at run-time. The dependency will be available at compile time, but not packaged into the artifact.
An example of the usage is the &lt;strong&gt;javax.servlet-api&lt;/strong&gt; dependency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;runtime&lt;/strong&gt;: The dependencies defined with this scope will be only available at runtime but not at compile time.
An example of the usage:
Imagine if you are using MySQL Driver inside your project, you can add the dependency with scope as runtime, to ensure that the JDBC API abstraction is used instead of MySQL Driver API during implementation.
If the source code includes any classes which is part of the MySQL JDBC API, then the code wont compile as the dependency is unavailable at compile time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;test&lt;/strong&gt;: Dependencies are only available at the time of running the tests, typical examples include Junit and TestNG&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;system&lt;/strong&gt;: It’s similar to the provided scope, but only difference is we need to explicitly mention where can the dependency be found in the system, using the &lt;strong&gt;systemPath&lt;/strong&gt; tag:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;systemPath&amp;gt;${basedir}/lib/some-dependency.jar&amp;lt;/systemPath&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Repositories&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In the previous section, we saw how Maven manages and automatically downloads the dependencies.&lt;/p&gt;

&lt;p&gt;These dependencies, are stored inside a special directory called &lt;strong&gt;Repository&lt;/strong&gt;. There are basically 2 kinds of repositories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Repository&lt;/strong&gt;
A Local Repository is a directory on the machine where the Maven is running.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The default location for the Local Repository is /.m2&lt;/p&gt;

&lt;p&gt;In Windows, it looks like:&lt;br&gt;
&lt;strong&gt;C:\Users&amp;lt;user-name&amp;gt;.m2\repository&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Remote Repository&lt;/strong&gt;
A Remote Repository is a web-site where we can download Maven Dependencies. This can be a repository provided by Maven (repo.maven.org) or a custom repository setup inside an organization using software like &lt;a href="https://jfrog.com/artifactory/" rel="noopener noreferrer"&gt;Artifactory&lt;/a&gt; or &lt;a href="https://www.sonatype.com/nexus/repository-pro" rel="noopener noreferrer"&gt;Nexus&lt;/a&gt;.
Now that we saw different types of repositories, let’s see how Maven Resolves the dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s see how Maven Resolves the dependencies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FRepositories.png%3Fw%3D631%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fprogrammingtechie.com%2Fwp-content%2Fuploads%2F2020%2F12%2FRepositories.png%3Fw%3D631%26ssl%3D1" alt="Maven Dependency Resolution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you define a dependency defined inside the &lt;strong&gt;pom.xml&lt;/strong&gt; file, Maven first checks whether the dependency is already present in the &lt;strong&gt;Local Repository&lt;/strong&gt; or not.&lt;/li&gt;
&lt;li&gt;If it is not, then it tries to connect to the &lt;strong&gt;Remote Repository&lt;/strong&gt;, (Ex: &lt;strong&gt;&lt;a href="https://repo.maven.org" rel="noopener noreferrer"&gt;https://repo.maven.org&lt;/a&gt;&lt;/strong&gt;) and tries to download the dependencies, and store them inside the &lt;strong&gt;Local Repository&lt;/strong&gt;.
We can define the &lt;strong&gt;Remote Repository&lt;/strong&gt; in our pom.xml like below:
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;
  &lt;br&gt;
    my-internal-site&lt;br&gt;
    &lt;a href="http://myserver/repo" rel="noopener noreferrer"&gt;http://myserver/repo&lt;/a&gt;&lt;br&gt;
  &lt;br&gt;
&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###Snapshot and Release Version Handling&amp;lt;a name="chapter-16"&amp;gt;&amp;lt;/a&amp;gt;
In the previous section, we learned that Maven first checks the **Local Repository** before downloading a dependency from **Remote Repository**.

When dealing with **SNAPSHOT** dependencies Maven **periodically** downloads the dependency from **Remote Repository** even though the dependency exists in **Local Repository**.

This is because **SNAPSHOT** dependencies are under heavy development, and are subjected to change frequently.

You can change this behavior by adding a **&amp;lt;snapshots&amp;gt;** section inside the **repositories** tag.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;
  &lt;br&gt;
    my-internal-site&lt;br&gt;
    &lt;a href="http://myserver/repo" rel="noopener noreferrer"&gt;http://myserver/repo&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
        true&lt;br&gt;
        XXX&lt;br&gt;
    &lt;br&gt;
  &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The value XXX inside the **updatePolicy** can be:

* **always**: Maven always checks for a latest version
* **daily**: This is the default value, as the name suggests it downloads the version once every day on the first run.
* **interval:XXX**: Checks every XXX minutes
* **never**: Never checks for the updates.

**RELEASE** versions on the other hand are more stable, and follow the usual dependency resolution.

# Maven Build Lifecycle&amp;lt;a name="chapter-17"&amp;gt;&amp;lt;/a&amp;gt;
Till now we learned about the Core Concepts of Maven, now it’s time to dive deep and understand how Maven builds our Java Project.

Maven follows a **Build Lifecycle** to well… build our project. 

This Lifecycle is divided into 3 parts:
* default
* clean
* site

Each Lifecycle is independent of each other and they can be executed together.

The default life cycle is divided into different phases like below:

* **validate** – verifies whether the pom.xml file is valid or not
* **compile** – compiles the source code inside the project
* **test** – runs unit-tests inside the project
* **package** – packages the source code into an artifact (ZIP, JAR, WAR or EAR)
* **integration-test**– executes tests marked as Integration Tests
* **verify** – checks whether the created package is valid or not.
* **install** – installs the created package into our Local Repository
* **deploy** – deploys the created package to the Remote Repository

The **clean** lifecycle is mainly responsible to clean the .class and meta-data generated by the above build phases.

The **site** lifecycle phase is responsible to generate Java Documentation.

All 3 lifecycles also contains some additional phases, which I am not going to cover in this tutorial, if you are interested you can refer to the [Maven Documentation](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#lifecycle-reference)

# Plugins and Goals&amp;lt;a name="chapter-18"&amp;gt;&amp;lt;/a&amp;gt;
To be able to execute these Lifecycle Phases, Maven provides us with **Plugins** to perform each task.

Each plugin is associated with a particular **Goal**

Let’s have a look at different Plugins and the associated Goals:

##Maven Compile Plugin&amp;lt;a name="chapter-19"&amp;gt;&amp;lt;/a&amp;gt;
The Maven Compile Plugin is responsible to compile our Java files into the .class files. It’s equivalent of running **javac &amp;lt;java-class-name&amp;gt;**

This plugin enables the **compile** phase of the default lifecycle.

You can add this plugin to your project by adding the below section to your **pom.xml** file under the **dependencies** 
section.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;
    &lt;br&gt;
        &lt;br&gt;
            org.apache.maven.plugins&lt;br&gt;
            maven-compiler-plugin&lt;br&gt;
            3.8.1&lt;br&gt;
        &lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;At the time of writing this tutorial, **Maven Compiler Plugin** is at version **3.8.1**

After adding the plugin to the project, you can activate the **compile** phase, by typing the below command:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn compiler:compile&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-cli) @ maven-project ---&lt;br&gt;
[INFO] Nothing to compile - all classes are up to date&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  0.729 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T20:16:23+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In the above command the **compiler** is the name of the plugin and **compile** is the goal which triggers the lifecycle phase – compile

You can already see the message – **“Nothing to compile – all classes are up to date”**

As there are no Java Files in our project, there is nothing to compile, so let’s create a simple **HelloWorld.java** file

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;public class HelloWorld {&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        System.out.println("Hello World");&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If you try to compile again, you can see the following output:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;$ mvn compiler:compile&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-cli) @ maven-project ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\target\classes&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  1.123 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T20:14:55+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;We can see the generated class files under the target folder which resides just under the project root folder.

![Maven Compile Folder Structure](https://i2.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Target-Folder.png?w=464&amp;amp;ssl=1)

If you have some Test files, those are also compiled using the **Compiler Plugin**.

To demonstrate that let’s create the below Test class under the src/test/java folder

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;public class HelloWorldTest {&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        HelloWorld helloWorld = new HelloWorld();&lt;br&gt;
        System.out.println(helloWorld.say("Hi"));&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;And here is how you can compile the test classes:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;$ mvn compiler:testCompile&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-cli) @ maven-project ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\target\test-classes&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  1.319 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T20:23:59+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;As you can see that a change has been detected by the **Maven Compiler Plugin** and it has compiled our Test classes to the **target/test-classes** folder

![Maven Test Compile](https://i0.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Target-Folder-with-Test-Classes.png?w=454&amp;amp;ssl=1)

As we are using IntelliJ, we can also use it to run the compilation, by clicking on the **compile** button under the **LifeCycle** dropdown as you see in the below image:

![Maven Intellij Lifecycle phases](https://i0.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Intellij-Compile-Plugin.png?w=616&amp;amp;ssl=1)

If you run the **compile** option you may see the below error:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;[INFO] Compiling 1 source file to F:\maven-project\target\classes&lt;br&gt;
[INFO] -------------------------------------------------------------&lt;br&gt;
[ERROR] COMPILATION ERROR : &lt;br&gt;
[INFO] -------------------------------------------------------------&lt;br&gt;
[ERROR] Source option 6 is no longer supported. Use 7 or later.&lt;br&gt;
[ERROR] Target option 6 is no longer supported. Use 7 or later.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is because, by default the **Source** and **Target** Compiler Version is set to 1.5 in IntelliJ Configuration. You can add the below **configuration** to the compiler plugin to override this settings:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;
    &lt;br&gt;
        &lt;br&gt;
            org.apache.maven.plugins&lt;br&gt;
            maven-compiler-plugin&lt;br&gt;
            3.8.1&lt;br&gt;
            &lt;br&gt;
                15&lt;br&gt;
                15&lt;br&gt;
            &lt;br&gt;
        &lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can pass many customized option to the Maven Compiler Plugin based on your needs, you can find the examples of the configuration in the [Apache Maven Compiler Plugin](https://maven.apache.org/plugins/maven-compiler-plugin/index.html) website

##Maven Surefire Plugin&amp;lt;a name="chapter-20"&amp;gt;&amp;lt;/a&amp;gt;
Using **Surefire Plugin**, we can run the tests inside our project by using the following command:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn test&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ maven-project ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ maven-project ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\target\test-classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ maven-project ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] -------------------------------------------------------&lt;br&gt;
[INFO]  T E S T S&lt;br&gt;
[INFO] -------------------------------------------------------&lt;br&gt;
[INFO] Running HelloWorldTest&lt;br&gt;
Hi&lt;br&gt;
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.014 s - in HelloWorldTest&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] Results:&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  4.797 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T20:54:49+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can see that the HelloWorldTest.java file was executed successfully, and the you can also see how many Tests are executed successfully.

The Surefire Plugin generates Text and XML reports under the **target/surefire-reports** folder.

![Maven Tests](https://i1.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Maven-SureFire-Reports.png?w=830&amp;amp;ssl=1)

Similar to **Compiler Plugin**, you can also configure Surefire Plugin based on your needs.

Surefire Plugin by default includes all tests, if you have a bunch of tests, you can manually exclude some tests to be executed using below configuration:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;
    org.apache.maven.plugins&lt;br&gt;
    maven-surefire-plugin&lt;br&gt;
    2.22.2&lt;br&gt;
    &lt;br&gt;
        HelloWorldTest.java&lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;And if you run the **mvn test** command now, you can see that no tests are executed.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn test&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ maven-project ---&lt;br&gt;
[INFO] Nothing to compile - all classes are up to date&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ maven-project ---&lt;br&gt;
[INFO] Nothing to compile - all classes are up to date&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ maven-project ---&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  1.043 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T21:00:09+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Maven Install Plugin&amp;lt;a name="chapter-21"&amp;gt;&amp;lt;/a&amp;gt;
This is used to package our source code into an artifact of our choice like a JAR and install it to our **Local Repository** which is **&amp;lt;USER_HOME&amp;gt;/.m2/repository** folder.

You can configure Maven Install Plugin by adding the below code:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;
    org.apache.maven.plugins&lt;br&gt;
    maven-install-plugin&lt;br&gt;
    2.5.2&lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can run the **install** phase of the lifecycle by typing the below command:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn install&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ maven-project ---&lt;br&gt;
[INFO] Nothing to compile - all classes are up to date&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-project ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ maven-project ---&lt;br&gt;
[INFO] Nothing to compile - all classes are up to date&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ maven-project ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven-project ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\target\maven-project-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ maven-project ---&lt;br&gt;
[INFO] Installing F:\maven-project\target\maven-project-1.0-SNAPSHOT.jar to C:\Users\sai.m2\repository\org\example\maven-project\1.0-SNAPSHOT\maven-project-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\pom.xml to C:\Users\sai.m2\repository\org\example\maven-project\1.0-SNAPSHOT\maven-project-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  1.236 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T21:10:49+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;By checking the above output, you can see that the install phase includes also the previous phases in the lifecycle, so as part of this phase maven:

* validates our pom.xml (**validate**)
* compiles our source code (**compile**)
* executes our tests (**test**)
* packages our source code into JAR (**package**)
* installs the JAR into our local repository (**install**)

You can see the JAR file in the below screenshot under the **target** folder.

![Maven Install Folder Structure](https://i0.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Intellij-Install-Plugin.png?w=759&amp;amp;ssl=1)

##Maven Deploy Plugin&amp;lt;a name="chapter-22"&amp;gt;&amp;lt;/a&amp;gt;
The Maven Deploy Plugin will deploy the artifact into a remote repository. The deploy goal of the plugin is associated with the **deploy** phase of the build lifecycle.

The plugin can be configured like below:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;
   org.apache.maven.plugins&lt;br&gt;
   maven-deploy-plugin&lt;br&gt;
   2.8.2&lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before running the **deploy** phase of the lifecycle, we have to make sure that the remote repository details are configured inside our project.

We can configure this details inside the **distributionManagement** section:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;
    &lt;br&gt;
        test-distribution&lt;br&gt;
        distro name&lt;br&gt;
        &lt;a href="http://distrourl.com" rel="noopener noreferrer"&gt;http://distrourl.com&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To be able to connect to the remote repository, maven needs access to the credentials, which can be configured inside a special file called as **settings.xml** file.

This file is usually configured inside the **&amp;lt;USER_HOME&amp;gt;/.m2/** folder, which looks like something below:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"&amp;gt;&lt;br&gt;
    &lt;br&gt;
        &lt;br&gt;
            test-distribution&lt;br&gt;
            my_username&lt;br&gt;
            my_password&lt;br&gt;
        &lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Maven also provides us a way to encrypt the credentials inside the **settings.xml** file, you can read about this here

You can run the **deploy** goal using the following command:
`$ mvn deploy`

Once you run this command, you will notice that it will run all the lifecycle phases up until deploy.

Although if you run this command in the example project, it will fail because the Remote Repository Details are invalid.

##Maven Clean Plugin&amp;lt;a name="chapter-23"&amp;gt;&amp;lt;/a&amp;gt;
Another important plugin in Maven is the **Maven Clean Plugin**, you saw that when running the above lifecycle phases, the generated files are stored under a folder called **target**.

Usually when building our source code we need to start of as a clean slate so that there are no inconsistencies in the generated class files or JAR.

For this reason we have the **clean** phase where we will delete all the contents inside the **target** folder. You can execute this phase by typing the below commands:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn clean&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-project ---&lt;br&gt;
[INFO] Deleting F:\maven-project\target&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  0.204 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T21:19:12+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can see that the target folder under our project is deleted successfully.

## Other Maven Plugins&amp;lt;a name="chapter-24"&amp;gt;&amp;lt;/a&amp;gt;
There are many other plugins in Maven world, to execute other phases in the Maven Build Lifecycle, you can check them out [here](https://maven.apache.org/plugins/index.html)

#Maven Multi Module Projects&amp;lt;a name="chapter-25"&amp;gt;&amp;lt;/a&amp;gt;
Till now we saw the Core Concepts of Maven, now it’s time to dive deep into some advanced concepts.

In the real world where we are building some non-trivial projects, the source code is going to be modularized (hopefully) and is divided into different sub projects.

To manage this effectively, Maven provides us Multi Module Projects where you can have nest different projects inside each other. We are basically creating a parent-child relationship between different Maven projects.

Basically, we have a **Parent Project** (Parent POM) which contains different **sub-projects** (**sub-modules**), each of which is again a normal Maven Project.

![Multi Module Project](https://i1.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Maven-Multi-Module-Project.png?w=506&amp;amp;ssl=1)

The **Parent POM** usually encapsulates other child’s and that’s why its packaged as a **POM** instead of usual packaing format’s like **JAR**.

If you recall the section **Project Object Model** , we discussed about **Super POM** which is basically a kind of **Parent POM** which encapsulates default settings configured by Maven for us.

##Creating Multi Module Project using IntelliJ&amp;lt;a name="chapter-26"&amp;gt;&amp;lt;/a&amp;gt;
We will see how to generate Multi Module Projects using our IntelliJ IDE.

To create the project, first right click on the project root folder and select **New** -&amp;gt; **Module** and click on **Next**.

![Maven Module Coordinates](https://i2.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Maven-Child-Project-1.png?w=1061&amp;amp;ssl=1)

Give a name to the child project and click on **Finish**.

![Maven Module Structure](https://i1.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Maven-Multi-Module-Project-Structure.png?w=730&amp;amp;ssl=1)

You can see the new project structure in the above picture after we created the **child project**.

Now if you open the **pom.xml** under the root folder, you can observe the following tags which are added by creating the maven module.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;modules&amp;gt;
    &amp;lt;module&amp;gt;child-project-1&amp;lt;/module&amp;gt;
&amp;lt;/modules&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;We can create multiple projects in the same way and you can see all the modules will be listed one-by-one under the **modules** tag.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;modules&amp;gt;
    &amp;lt;module&amp;gt;child-project-1&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-2&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-3&amp;lt;/module&amp;gt;
&amp;lt;/modules&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;As we create these 3 modules, having the **src** folder under the root project folder doesn’t make much sense, so let’s copy and paste this folder onto other child-projects, so that we have some code configured inside these modules.

This is how our project structure now looks like:
![Maven Multi Module Project Structure](https://i2.wp.com/programmingtechie.com/wp-content/uploads/2020/12/Maven-Multi-Module-Project-Structure-with-Code.png?w=944&amp;amp;ssl=1)

And if you check the **pom.xml** of **child-project-1**,**child-project-2** and **child-project-3**. You can see that the root project is configured as a parent project.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br&gt;
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;&lt;br&gt;
    &lt;br&gt;
        maven-project&lt;br&gt;
        org.example&lt;br&gt;
        1.0-SNAPSHOT&lt;br&gt;
    &lt;br&gt;
    4.0.0&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;artifactId&amp;gt;child-project-1&amp;lt;/artifactId&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Now you can build all the projects at once by running the **mvn install** under the Parent Project, and Maven scans through all the POMS and builds all of them one-by-one

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;$ mvn install&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Reactor Build Order:&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] maven-project                                                      [pom]&lt;br&gt;
[INFO] child-project-1                                                    [jar]&lt;br&gt;
[INFO] child-project-2                                                    [jar]&lt;br&gt;
[INFO] child-project-3                                                    [jar]&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT                                [1/4]&lt;br&gt;
[INFO] --------------------------------[ pom ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ maven-project ---&lt;br&gt;
[INFO] Installing F:\maven-project\pom.xml to C:\Users\subra.m2\repository\org\example\maven-project\1.0-SNAPSHOT\maven-project-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-1 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-1 1.0-SNAPSHOT                              [2/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-1 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-1 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-1\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-1 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\child-project-1\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-1 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-1\target\test-classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-1 ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-1 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-1\target\child-project-1-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-1 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-1\target\child-project-1-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-1\1.0-SNAPSHOT\child-project-1-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-1\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-1\1.0-SNAPSHOT\child-project-1-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-2 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-2 1.0-SNAPSHOT                              [3/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-2 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-2 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-2\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-2 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\child-project-2\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-2 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-2\target\test-classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-2 ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-2 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-2\target\child-project-2-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-2 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-2\target\child-project-2-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-2\1.0-SNAPSHOT\child-project-2-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-2\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-2\1.0-SNAPSHOT\child-project-2-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-3 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-3 1.0-SNAPSHOT                              [4/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-3 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-3 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-3\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-3 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] skip non existing resourceDirectory F:\maven-project\child-project-3\src\test\resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-3 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-3\target\test-classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-3 ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-3 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-3\target\child-project-3-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-3 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-3\target\child-project-3-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-3\1.0-SNAPSHOT\child-project-3-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-3\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-3\1.0-SNAPSHOT\child-project-3-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Reactor Summary for maven-project 1.0-SNAPSHOT:&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] maven-project ...................................... SUCCESS [  0.252 s]&lt;br&gt;
[INFO] child-project-1 .................................... SUCCESS [  1.534 s]&lt;br&gt;
[INFO] child-project-2 .................................... SUCCESS [  0.430 s]&lt;br&gt;
[INFO] child-project-3 .................................... SUCCESS [  0.351 s]&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  2.699 s&lt;br&gt;
[INFO] Finished at: 2020-12-04T21:58:10+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can see that Maven built all the projects and provided us a nice report of the **Build Status** of each project.

Maven uses something called as a **Reactor** which is responsible to scan the whole project and identify the parent and child maven projects. If there are any dependencies, then Reactor makes sure to execute the projects in the required order.

For example, if **child-project-2** is dependent on **child-project-3** , then Maven Reactor makes sure to first build **child-project-3** and then **child-project-2**.

##Managing Dependencies inside Maven Multi Module Project&amp;lt;a name="chapter-27"&amp;gt;&amp;lt;/a&amp;gt;
When you are working with Multiple Maven Modules, you may be working with different dependencies in different modules, and chances are that you may be using similar dependencies in multiple modules.

Maven provides us a way to effectively manage the dependencies in your project by allowing us to define the dependencies in centralized location (**parent project**) and use those dependencies across the different child projects.

This minimizes the dependency version mismatch across multiple projects, as we have a single place we can manage all the dependencies and its versions.

Let’s see how to do that in our example project.

I am going to move all the dependencies which are defined inside the parent project into the **dependencyManagement** section, like below:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br&gt;
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;&lt;br&gt;
    4.0.0&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
&amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
&amp;lt;packaging&amp;gt;pom&amp;lt;/packaging&amp;gt;
&amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
&amp;lt;modules&amp;gt;
    &amp;lt;module&amp;gt;child-project-1&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-2&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-3&amp;lt;/module&amp;gt;
&amp;lt;/modules&amp;gt;

&amp;lt;dependencyManagement&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.junit.jupiter&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;junit-jupiter-engine&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;5.5.2&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-test&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.1.6.RELEASE&amp;lt;/version&amp;gt;
            &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
            &amp;lt;exclusions&amp;gt;
                &amp;lt;exclusion&amp;gt;
                    &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
                    &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
                &amp;lt;/exclusion&amp;gt;
            &amp;lt;/exclusions&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;
&amp;lt;/dependencyManagement&amp;gt;

&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;source&amp;gt;11&amp;lt;/source&amp;gt;
                &amp;lt;target&amp;gt;11&amp;lt;/target&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.22.2&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;excludes&amp;gt;HelloWorldTest.java&amp;lt;/excludes&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-install-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.5.2&amp;lt;/version&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The change in the pom.xml is minor, we just moved the dependencies under the **dependencyManagement** tag.

Now if you analyze the dependencies under the **child-project-1** you can see that it’s empty.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;mvn dependency:tree&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-1 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-1 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ child-project-1 ---&lt;br&gt;
[INFO] org.example:child-project-1:jar:1.0-SNAPSHOT&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  0.871 s&lt;br&gt;
[INFO] Finished at: 2020-12-05T20:23:59+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is because we moved all the dependencies inside the Parent POM into **dependencyManagement** section, now to access any dependencies the **Child Projects** should define them manually inside their **pom.xml**.

In this way, the child projects can have only the dependencies they need inside the **pom.xml**.

Now, let’s go ahead and add the **junit-jupiter** dependencies inside the **child-project-1** and see what happens.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br&gt;
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;&lt;br&gt;
    &lt;br&gt;
        maven-project&lt;br&gt;
        org.example&lt;br&gt;
        1.0-SNAPSHOT&lt;br&gt;
    &lt;br&gt;
    4.0.0&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;artifactId&amp;gt;child-project-1&amp;lt;/artifactId&amp;gt;
&amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.junit.jupiter&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;junit-jupiter-engine&amp;lt;/artifactId&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;$ mvn dependency:tree&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-1 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-1 1.0-SNAPSHOT&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ child-project-1 ---&lt;br&gt;
[INFO] org.example:child-project-1:jar:1.0-SNAPSHOT&lt;br&gt;
[INFO] - org.junit.jupiter:junit-jupiter-engine:jar:5.5.2:compile&lt;br&gt;
[INFO]    +- org.apiguardian:apiguardian-api:jar:1.1.0:compile&lt;br&gt;
[INFO]    +- org.junit.platform:junit-platform-engine:jar:1.5.2:compile&lt;br&gt;
[INFO]    |  +- org.opentest4j:opentest4j:jar:1.2.0:compile&lt;br&gt;
[INFO]    |  - org.junit.platform:junit-platform-commons:jar:1.5.2:compile&lt;br&gt;
[INFO]    - org.junit.jupiter:junit-jupiter-api:jar:5.5.2:compile&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  0.930 s&lt;br&gt;
[INFO] Finished at: 2020-12-05T20:27:26+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can now see that the **junit-jupiter** dependency is available inside the **child-project-1**.

##Managing Plugins inside Maven Multi Module Project&amp;lt;a name="chapter-28"&amp;gt;&amp;lt;/a&amp;gt;
We can also manage Plugins inside our Maven Multi Module project, similar to the dependencies.

To Manage Plugins, we have the **pluginManagement** section inside the **pom.xml** and each child project can chose the plugin it needs.

This is how our parent **pom.xml** looks like after introducing the **pluginManagement**.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br&gt;
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;&lt;br&gt;
    4.0.0&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
&amp;lt;artifactId&amp;gt;maven-project&amp;lt;/artifactId&amp;gt;
&amp;lt;packaging&amp;gt;pom&amp;lt;/packaging&amp;gt;
&amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
&amp;lt;modules&amp;gt;
    &amp;lt;module&amp;gt;child-project-1&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-2&amp;lt;/module&amp;gt;
    &amp;lt;module&amp;gt;child-project-3&amp;lt;/module&amp;gt;
&amp;lt;/modules&amp;gt;

&amp;lt;dependencyManagement&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.junit.jupiter&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;junit-jupiter-engine&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;5.5.2&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-test&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.1.6.RELEASE&amp;lt;/version&amp;gt;
            &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
            &amp;lt;exclusions&amp;gt;
                &amp;lt;exclusion&amp;gt;
                    &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
                    &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
                &amp;lt;/exclusion&amp;gt;
            &amp;lt;/exclusions&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;
&amp;lt;/dependencyManagement&amp;gt;

&amp;lt;build&amp;gt;
    &amp;lt;pluginManagement&amp;gt;
        &amp;lt;plugins&amp;gt;
            &amp;lt;plugin&amp;gt;
                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
                &amp;lt;configuration&amp;gt;
                    &amp;lt;source&amp;gt;11&amp;lt;/source&amp;gt;
                    &amp;lt;target&amp;gt;11&amp;lt;/target&amp;gt;
                &amp;lt;/configuration&amp;gt;
            &amp;lt;/plugin&amp;gt;
            &amp;lt;plugin&amp;gt;
                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;2.22.2&amp;lt;/version&amp;gt;
                &amp;lt;configuration&amp;gt;
                    &amp;lt;excludes&amp;gt;HelloWorldTest.java&amp;lt;/excludes&amp;gt;
                &amp;lt;/configuration&amp;gt;
            &amp;lt;/plugin&amp;gt;
            &amp;lt;plugin&amp;gt;
                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;maven-install-plugin&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;2.5.2&amp;lt;/version&amp;gt;
            &amp;lt;/plugin&amp;gt;
        &amp;lt;/plugins&amp;gt;
    &amp;lt;/pluginManagement&amp;gt;
&amp;lt;/build&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Using Profiles&amp;lt;a name="chapter-29"&amp;gt;&amp;lt;/a&amp;gt;
Profiles can be used in Maven to created customized build configurations. This means customizing the behavior of our builds based on specific conditions.

For example: Sometimes we need to test whether the source code packaging is working correctly or not, in that case we can skip the test execution by activating the **skip.tests** property like below:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;
    skip-tests&lt;br&gt;
    &lt;br&gt;
        true&lt;br&gt;
    &lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Now we can try to run the build by specifying which profile to activate using the **-P** flag.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;$ mvn -Pskip-tests clean install&lt;br&gt;
[INFO] Scanning for projects...&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Reactor Build Order:&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] maven-project                                                      [pom]&lt;br&gt;
[INFO] child-project-1                                                    [jar]&lt;br&gt;
[INFO] child-project-2                                                    [jar]&lt;br&gt;
[INFO] child-project-3                                                    [jar]&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] ---------------------&amp;lt; org.example:maven-project &amp;gt;----------------------&lt;br&gt;
[INFO] Building maven-project 1.0-SNAPSHOT                                [1/4]&lt;br&gt;
[INFO] --------------------------------[ pom ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-project ---&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ maven-project ---&lt;br&gt;
[INFO] Installing F:\maven-project\pom.xml to C:\Users\subra.m2\repository\org\example\maven-project\1.0-SNAPSHOT\maven-project-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-1 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-1 1.0-SNAPSHOT                              [2/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child-project-1 ---&lt;br&gt;
[INFO] Deleting F:\maven-project\child-project-1\target&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-1 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-1 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-1\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-1 ---&lt;br&gt;
[INFO] Not copying test resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-1 ---&lt;br&gt;
[INFO] Not compiling test sources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-1 ---&lt;br&gt;
[INFO] Tests are skipped.&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-1 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-1\target\child-project-1-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-1 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-1\target\child-project-1-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-1\1.0-SNAPSHOT\child-project-1-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-1\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-1\1.0-SNAPSHOT\child-project-1-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-2 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-2 1.0-SNAPSHOT                              [3/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child-project-2 ---&lt;br&gt;
[INFO] Deleting F:\maven-project\child-project-2\target&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-2 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-2 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-2\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-2 ---&lt;br&gt;
[INFO] Not copying test resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-2 ---&lt;br&gt;
[INFO] Not compiling test sources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-2 ---&lt;br&gt;
[INFO] Tests are skipped.&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-2 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-2\target\child-project-2-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-2 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-2\target\child-project-2-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-2\1.0-SNAPSHOT\child-project-2-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-2\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-2\1.0-SNAPSHOT\child-project-2-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --------------------&amp;lt; org.example:child-project-3 &amp;gt;---------------------&lt;br&gt;
[INFO] Building child-project-3 1.0-SNAPSHOT                              [4/4]&lt;br&gt;
[INFO] --------------------------------[ jar ]---------------------------------&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child-project-3 ---&lt;br&gt;
[INFO] Deleting F:\maven-project\child-project-3\target&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child-project-3 ---&lt;br&gt;
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!&lt;br&gt;
[INFO] Copying 0 resource&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child-project-3 ---&lt;br&gt;
[INFO] Changes detected - recompiling the module!&lt;br&gt;
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!&lt;br&gt;
[INFO] Compiling 1 source file to F:\maven-project\child-project-3\target\classes&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child-project-3 ---&lt;br&gt;
[INFO] Not copying test resources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ child-project-3 ---&lt;br&gt;
[INFO] Not compiling test sources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-3 ---&lt;br&gt;
[INFO] Tests are skipped.&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-3 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-3\target\child-project-3-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ child-project-3 ---&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-3\target\child-project-3-1.0-SNAPSHOT.jar to C:\Users\subra.m2\repository\org\example\child-project-3\1.0-SNAPSHOT\child-project-3-1.0-SNAPSHOT.jar&lt;br&gt;
[INFO] Installing F:\maven-project\child-project-3\pom.xml to C:\Users\subra.m2\repository\org\example\child-project-3\1.0-SNAPSHOT\child-project-3-1.0-SNAPSHOT.pom&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Reactor Summary for maven-project 1.0-SNAPSHOT:&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] maven-project ...................................... SUCCESS [  0.327 s]&lt;br&gt;
[INFO] child-project-1 .................................... SUCCESS [  1.208 s]&lt;br&gt;
[INFO] child-project-2 .................................... SUCCESS [  0.205 s]&lt;br&gt;
[INFO] child-project-3 .................................... SUCCESS [  0.167 s]&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] BUILD SUCCESS&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;br&gt;
[INFO] Total time:  2.055 s&lt;br&gt;
[INFO] Finished at: 2020-12-05T23:00:13+01:00&lt;br&gt;
[INFO] ------------------------------------------------------------------------&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If you observe the logs carefully, you can see that the test-execution is skipped:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;[INFO] Not compiling test sources&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ child-project-3 ---&lt;br&gt;
[INFO] Tests are skipped.&lt;br&gt;
[INFO]&lt;br&gt;
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child-project-3 ---&lt;br&gt;
[INFO] Building jar: F:\maven-project\child-project-3\target\child-project-3-1.0-SNAPSHOT.jar&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is just a simple usage of the profiles, you can configure multiple profiles in our project to customize the build behavior.

# Conclusion&amp;lt;a name="chapter-30"&amp;gt;&amp;lt;/a&amp;gt;

So we came to the end of this tutorial, I hope this tutorial improved your understanding of Maven.

#### If you like this article please make sure to share it with your friends and colleagues who wants to learn about Apache Maven. You can follow me through my [blog](https://https://programmingtechie.com/), [Youtube Channel](https://www.youtube.com/channel/UCD20RZV_WHQImisCW2QZwDw) and [Twitter](https://twitter.com/sai90_u)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>java</category>
      <category>maven</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Build a Reddit Clone using Spring Boot and Angular</title>
      <dc:creator>Sai Upadhyayula</dc:creator>
      <pubDate>Tue, 08 Dec 2020 19:13:51 +0000</pubDate>
      <link>https://dev.to/saiupadhyayula/build-a-reddit-clone-using-spring-boot-and-angular-1e4c</link>
      <guid>https://dev.to/saiupadhyayula/build-a-reddit-clone-using-spring-boot-and-angular-1e4c</guid>
      <description>&lt;p&gt;In this tutorial series, we are going to build a Reddit Clone application with Spring boot and Angular.&lt;/p&gt;

&lt;p&gt;We will be using Spring Boot, Spring Security, Spring Data JPA, MySQL on the back-end side and on the front end we will be using Angular and Bootstrap.&lt;/p&gt;

&lt;p&gt;Also, we will be using Token Based Authentication in the form of JSON Web Tokens (JWT).&lt;/p&gt;

&lt;p&gt;The main idea of this series of tutorials is to show how to use these technologies to build a simple web application.&lt;/p&gt;

&lt;p&gt;You can find the complete playlist on Youtube :&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/7PsjGI-88sc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you learn quickly by reading through written tutorials, you can also check the written version of this tutorial &lt;a href="https://programmingtechie.com/2020/05/14/building-a-reddit-clone-with-spring-boot-and-angular/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/sai90_u"&gt;Twitter&lt;/a&gt; to get latest updates on the blog posts and Video Tutorials.&lt;/p&gt;

</description>
      <category>java</category>
      <category>spring</category>
      <category>springboot</category>
      <category>angular</category>
    </item>
  </channel>
</rss>
