What is the difference between Maven and Gradle in Java projects, and what do you need to know for an interview?
The difference is fundamentally one of declarative versus imperative configuration. Maven is declarative: you describe the project in a pom.xml and the plugin that reads it decides what to do. Gradle is imperative: you write a build script in a programming language and describe the tasks and their dependencies yourself. Maven's build file is XML describing coordinates and configuration; Gradle's is Groovy or Kotlin code.
What that means practically. Maven is easier to read for someone who has not seen it, because the file says what the project is rather than how to build it, and the same conventions apply to every project. Gradle is far more flexible — you can write a task that does something the plugin ecosystem has never heard of — but the flexibility means the build file becomes code that can be as messy as any other code.
For an interview, the useful knowledge is about dependencies and the module structure, because that is where the tooling actually affects your work. A Maven project has a fixed directory layout, with sources in a folder and resources in a folder, and the build produces a jar. A Gradle project expresses the same thing as a set of subprojects, each of which can be a library or an application, and it can produce jars, war files or native images.
The honest summary is that you should be able to read both build files, declare a dependency in both, and explain what a transitive dependency is. You do not need to be able to write a custom Gradle plugin, and nobody will ask.
Here is the same thing as runnable code:
public class Main {
public static void main(String[] args) {
// Maven: a pom.xml with an explicit dependency.
String pom = """
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
""";
System.out.println("Maven (pom.xml):");
System.out.println(pom);
// Gradle: a build script with a coordinate and a version.
String gradle = "implementation 'com.google.guava:guava:33.0.0-jre'";
System.out.println("Gradle (build.gradle):");
System.out.println(gradle);
// Both resolve to the same jar.
System.out.println("same coordinates: com.google.guava:guava:33.0.0-jre");
}
}