Project structure & build tools
Maven/Gradle standard layout, what pom.xml and build.gradle do, dependencies, and the commands you will type every day.
The standard project layout
Every Maven and Gradle project shares the same Standard Directory Layout by convention:
my-project/
├── src/
│ ├── main/
│ │ └── java/ ← production source
│ └── test/
│ └── java/ ← test source
├── pom.xml ← Maven descriptor
└── build.gradle ← Gradle descriptor
Your IDE and the build tool both expect this layout. Following it means tools, plugins, and every colleague will instantly navigate your project.
Maven in one page
pom.xml (Project Object Model) describes your project. A typical test dependency:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
Dependencies are downloaded from Maven Central on first use and cached in ~/.m2/repository. The scope controls availability: compile (default — always on classpath), test (test compilation and run only), provided (compile time only, not bundled).
Key commands:
| Command | Does |
|---|---|
| mvn compile | Compiles src/main/java |
| mvn test | Compiles and runs tests |
| mvn package | Produces the JAR in target/ |
| mvn clean | Deletes target/ |
Gradle in one page
build.gradle (Groovy DSL) or build.gradle.kts (Kotlin DSL) serves the same role:
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}
| Command | Does |
|---|---|
| gradle build | Compile + test + package |
| gradle test | Compile and run tests |
| gradle clean | Deletes build/ |
Wrapper scripts
Most projects ship a Maven Wrapper (mvnw) or Gradle Wrapper (gradlew). Use these instead of the globally installed tool — they download and use the exact version the project was built with, so CI and teammates get identical results.
You will spend your first weeks at any Java job running ./mvnw test or ./gradlew build. Knowing the layout and these commands is the entry ticket.