Builds, dependencies, versions, multi-module projects
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeThe main Maven lifecycle phases are validate, compile, test, package, verify, install, and deploy. Each phase represents a step in building and distributing a project, and plugins can attach goals to these phases.
In Maven, dependencies are declared in the <dependencies> section of the pom.xml file. You specify the groupId, artifactId, and version for each dependency.
You run a Gradle task by executing gradle <task-name> or ./gradlew <task-name> if you're using the wrapper. For example, ./gradlew build runs the build task.
Dependency scopes in Maven control where a dependency is available, such as during compilation, testing, or runtime. This helps manage classpaths and ensures dependencies are only used where needed.
Artifact repositories store build outputs and dependencies, allowing projects to share and reuse artifacts. Examples include Maven Central, Nexus, and Artifactory.
Gradle's Kotlin DSL (build.gradle.kts) provides type safety and better IDE support compared to Groovy. It helps catch errors at compile time and makes scripts easier to maintain, especially in large projects.
Maven automatically resolves transitive dependencies by including dependencies of your dependencies. It uses dependency mediation to select the version closest to the root, but this can lead to conflicts if multiple versions are present.
A BOM (Bill of Materials) is a special POM that lists dependency versions. In Maven, you import a BOM using <dependencyManagement>, and in Gradle, you can use platform dependencies. This ensures consistent versions across modules.
A Maven multi-module project has a parent POM with a <modules> section listing child modules. Each module has its own POM but inherits configuration from the parent, allowing shared dependencies and plugins.
To make builds reproducible, I use fixed dependency versions, avoid SNAPSHOTs, and configure plugins to produce deterministic outputs. I also verify checksums and use artifact repositories to ensure consistent dependencies.
I use tools like OWASP Dependency-Check for Maven or Gradle, which scan dependencies against known CVEs. These tools can be integrated into CI pipelines to generate reports and fail builds if vulnerabilities are found.
Gradle resolves dependency conflicts using a strategy called 'conflict resolution', which by default selects the highest version. You can customize this behavior with resolution rules or use BOMs for consistency.