All 15 Build Tools: Maven & Gradle questions
More in Build Tools: Maven & Gradle
Advertisement
Back to results for “UI Testing”
Java › Build Tools: Maven & Gradle

What is the standard Maven directory layout, and why does following this convention matter?

Beginner

Answer

Maven's convention-over-configuration philosophy defines a standard project structure: src/main/java for application source code, src/main/resources for non-code resources bundled into the artifact, src/test/java and src/test/resources for the equivalent test-scoped files, and target/ for build output -- following this convention means Maven's built-in plugins work correctly with zero explicit configuration, whereas deviating from it requires manually reconfiguring source directories in the pom.xml, adding unnecessary complexity for little benefit in most projects.
my-project/
  src/
    main/
      java/         <- application source code
      resources/    <- config files, bundled into the JAR
    test/
      java/         <- test source code
      resources/    <- test-only config files
  target/             <- compiled classes and packaged JAR go here
  pom.xml
Real-world example A new team member familiar with Maven conventions can immediately navigate any Maven-based project's source layout without reading any project-specific documentation, since src/main/java, src/test/java, and pom.xml are universally consistent across virtually all Maven projects.

Common follow-ups: How would you configure Maven to use a non-standard source directory layout, and what plugin settings does that require?;How does Gradle's default directory convention compare to Maven's?