Maven#

What is Maven?#

Pros:

  • Dependency Management

  • Industry Standard

  • Well Designed Structure

Cons:

  • Ramp-up

  • Structure can be overkill

  • Opaque mechanisms

    • If the build breaks, fixing it is tough!

POM.xml#

The pom.xml (Project Object Model) file is the core of a Maven project. It contains information about the project and configuration details used by Maven to build the project. Here’s a basic example of a pom.xml file and an explanation of its components:

POM == Project Object Model

<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>
</project>

Project File Structure#

Maven follows a mandatory and specific directory structure to maintain consistency and convention across projects. Here’s an overview of the Maven project structure :

my-app
β”‚
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ main
β”‚   β”‚   β”œβ”€β”€ java
β”‚   β”‚   β”‚   └── com
β”‚   β”‚   β”‚       └── example
β”‚   β”‚   β”‚           └── App.java
β”‚   β”‚   β”œβ”€β”€ resources
β”‚   β”‚   β”‚   └── application.properties
β”‚   β”œβ”€β”€ test
β”‚   β”‚   β”œβ”€β”€ java
β”‚   β”‚   β”‚   └── com
β”‚   β”‚   β”‚       └── example
β”‚   β”‚   β”‚           └── AppTest.java
β”‚   β”‚   β”œβ”€β”€ resources
β”‚   β”‚   β”‚   └── test-config.properties
β”‚
β”œβ”€β”€ pom.xml

Here is an explanation of the above. src/main/java: This directory contains your main application source code. The package structure should follow the standard Java package naming conventions (e.g., com.example). src/main/resources: This directory is for non-Java resources required by your application, such as configuration files, property files, XML files, etc. These resources are included in the classpath when the project is built. src/test/java: This directory contains your test source code. It follows the same package structure as your main source code. Test classes are typically named with a Test suffix (e.g., AppTest.java). src/test/resources: This directory is for resources needed by your tests, such as test configuration files, mock data, etc. These resources are also included in the classpath during the test phase. pom.xml: The Project Object Model file that contains information about the project and configuration details used by Maven to build the project. It includes dependencies, plugins, build configurations, and more.

In the CSS 490: Multithreading in GUI Application class, we have the following directory structure.

β”œβ”€β”€β”€.mvn
β”‚   └───wrapper
β”œβ”€β”€β”€.vscode
β”œβ”€β”€β”€lib
β”œβ”€β”€β”€logs
β”œβ”€β”€β”€src
β”‚   β”œβ”€β”€β”€main
β”‚   β”‚   β”œβ”€β”€β”€java
β”‚   β”‚   β”‚   └───com
β”‚   β”‚   β”‚       └───mrstride
β”‚   β”‚   β”‚           β”œβ”€β”€β”€console
β”‚   β”‚   β”‚           β”œβ”€β”€β”€gui
β”‚   β”‚   β”‚           └───services
β”‚   β”‚   └───resources
β”‚   β”‚       β”œβ”€β”€β”€designs
β”‚   β”‚       β”œβ”€β”€β”€images
β”‚   β”‚       β”œβ”€β”€β”€levels
β”‚   β”‚       └───playbacks
β”‚   └───test
β”‚       └───java
β”‚           └───com
β”‚               └───mrstride
└───target