0Pricing
Java Academy · Lesson

Maven Project Structure

POM, lifecycle, and dependencies.

Maven Project Structure is a free Java Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Maven Project Structure

Maven is a build tool and dependency manager built around a single principle: convention over configuration. Follow its standard layout and most things work with almost no setup. This lesson covers the layout, the POM, and dependency management.

The Standard Directory Layout

Maven expects a fixed structure:

  • src/main/java — production source code.
  • src/main/resources — production resources.
  • src/test/java — test source code.
  • target/ — build output (generated).

The POM

The heart of a Maven project is pom.xml — the Project Object Model. It declares coordinates, dependencies, plugins, and build settings in XML.

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
</project>

Coordinates: GAV

Every artifact is identified by groupId, artifactId, and version (GAV). These coordinates uniquely name your project and every dependency you pull in.

Declaring Dependencies

Dependencies are listed inside <dependencies>. Maven downloads them (and their transitive dependencies) from repositories like Maven Central into a local cache.

<dependencies>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.10.0</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Dependency Scopes

Scope controls when a dependency is on the classpath:

  • compile — everywhere (default).
  • provided — compile only; supplied at runtime by the container.
  • runtime — runtime and test, not compile.
  • test — test compilation and execution only.

Transitive Dependencies

If A depends on B and B depends on C, Maven gives you C automatically — that is transitivity. When versions conflict, Maven resolves them by the nearest definition in the dependency tree.

The Build Lifecycle

Maven defines an ordered lifecycle of phases. The default lifecycle includes (in order): validate, compile, test, package, verify, install, deploy. Running a phase runs all earlier phases too.

Common Commands

  • mvn compile — compile main sources.
  • mvn test — run unit tests.
  • mvn package — build the JAR/WAR into target/.
  • mvn install — copy the artifact to your local repo for other projects.

The Local Repository

Downloaded artifacts are cached in ~/.m2/repository. Subsequent builds reuse the cache instead of re-downloading. mvn install places your own artifact there so sibling projects can depend on it.

Multi-Module Projects

A parent POM with <packaging>pom</packaging> can list child <modules>. Maven builds them in dependency order, letting a large system share configuration and versions from one place.

Quick Check

Test your understanding of Maven structure.

Recap

You learned Maven's foundations:

  • Convention over configuration with the standard src/main/java layout.
  • The POM declares GAV coordinates, dependencies, and plugins.
  • Scopes (compile, provided, runtime, test) control classpath visibility.
  • Dependencies are transitive; conflicts resolve by nearest definition.
  • The ordered lifecycle means a phase runs all earlier phases.

Frequently asked questions

Is the “Maven Project Structure” lesson free?

Yes — the full text of “Maven Project Structure” is free to read here on the web, and the Java Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Maven Project Structure”?

POM, lifecycle, and dependencies. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Maven Project Structure” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Maven Project Structure
  2. Maven Plugins and Goals
  3. Gradle Basics
  4. Choosing a Build Tool
← Back to Java Academy