Last Updated : 04 Aug, 2025
Here is how internally the maven build process is done with testing test cases also:
graph TB
subgraph Project Structure
A[Project Source Code]
A1[pom.xml]
A2[src/main/java/com/example/App.java]
A3[src/test/java/com/example/AppTest.java]
end
subgraph Maven Commands
B[mvn validate]
C[mvn compile]
D[mvn test]
E[mvn package]
F[mvn verify]
G[mvn install]
H[mvn deploy]
endA --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
Description of Each Phase:
Here we created a sample Maven project using Spring Initializr with the required dependencies for the project. Below is the step-by-step process for building and testing a Maven project using Maven commands.
Step 1: Create a Sample Maven ProjectFirst create a sample maven project by using your favorite IDE. Here, we use Spring Tool Suite and select required dependencies for this project. Below are the dependencies.
Dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Project Structure:
Step 2: Write Sample Test CasesOnce project is created successfully, write sample test cases in the test class which is located in src/test/java location in the project.
MavenbuildApplicationTests.java:
Java
package com.app;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MavenbuildApplicationTests {
@Test
void contextLoads() {
}
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}
Step 3: Validate the Project
Now, open the command prompt and redirect to your project folder and run the following command to validate the project:
mvn validateOutput: Step 4: Compile the Source Code
Once successfully validated the project, we need to compile the source code.
mvn compileOutput: Step 5: Run Unit Tests
Now, Run the unit tests once compilation is completed.
mvn testOutput: Step 6: Package the Compiled Code
Now Package the compiled code.
mvn packageOutput: Step 7: Run Integration Tests and Verify
Run integration tests and perform additional verifications
mvn verifyOutput:
Maven Build Success:
Now, Install the package to Local Repository.
mvn installOutput:
Maven Build Success:
Now Deploy the package to Remote Repository.
mvn deployOutput:
Maven Build Success:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4