Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
With the big picture established, let’s take a piecewise approach to comparing Maven and Gradle. We will start with a reminder of the appearance of a barest bones Maven POM.
<!-- The smallest possible Maven POM.xml --> <project> <modelVersion>4.0.0</modelVersion> <groupId>com.gradleware.samples</groupId> <artifactId>sample01-barestbones</artifactId> <version>0.0.1-SNAPSHOT</version> </project> |
While often desirable to have the formal vectors of groupId, artifactId, and version for a build, there are equally times where it is overkill. No allowance is made for that in Maven. You must provide all the fields. Adding a final bit of cruft, you also need the modelVersion field, just in case Maven should ever decide to expand its vocabulary of tags (though it hasn’t since the release of Maven 2.0 in 2004).
Earlier in the book, we showed you just how simple it was to get started with Gradle, so we will leave the simplicity of that first Gradle build file to the earlier example, Section 1.4. We will use, as our first comparison with Maven, a Gradle build file in Example 4-2 that defines a few attributes and can produce a JAR, a common final product of a Java build.
apply plugin: 'java' |
That one line Gradle build file in Example 4-2, when executed with a mere gradle build from the command line, performed the following actions:
Downloaded any declared dependencies (none) to ~/.gradle/cache
Compiled the code in src/main/java
Wrote the class files into build/classes/main
Attempted to compile and run any unit tests (none)
Wrote unit test results in XML format to build/test-results/
Wrote an HTML-formatted unit test report to build/reports/tests/
Generated a MANIFEST.MF in build/tmp/jar/MANIFEST.MF
Compressed the .class files along with the MANIFEST.MF into a JAR in build/libs/maven-gradle-comparison-simple.jar
The described actions taken by Gradle are made evident by examining the files in the structure of the output directory.
build
├── classes
│ └── main
│ └── Main.class
├── dependency-cache
├── libs
│ └── maven-gradle-comparison-simple.jar
├── reports
│ └── tests
│ ├── css3-pie-1.0beta3.htc
│ ├── index.html
│ ├── report.js
│ └── style.css
├── test-results
└── tmp
└── jar
└── MANIFEST.MF |