A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/advance-java/maven-build-and-test-project/ below:

Maven - Build & Test Project

Maven - Build & Test Project

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]
end

A --> B


B --> C
C --> D
D --> E
E --> F
F --> G
G --> H

Description of Each Phase:

Build and Test Maven Project

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 Project

First 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 Cases

Once 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 validate
Output: Step 4: Compile the Source Code

Once successfully validated the project, we need to compile the source code.

mvn compile
Output: Step 5: Run Unit Tests

Now, Run the unit tests once compilation is completed.

mvn test
Output: Step 6: Package the Compiled Code

Now Package the compiled code.

mvn package
Output: Step 7: Run Integration Tests and Verify

Run integration tests and perform additional verifications

mvn verify
Output:


Maven Build Success:

Step 8: Install the Package to Local Repository

Now, Install the package to Local Repository.

mvn install
Output:


Maven Build Success:

Step 9: Deploy the Package to Remote Repository

Now Deploy the package to Remote Repository.

mvn deploy
Output:

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