Tutorial 1 Maven and Gradle - McGill-ECSE429-Winter2022/tutorials GitHub Wiki
Following the tutorial available at https://www.baeldung.com/maven, we will familiarize ourselves with Maven build automation tool. Through this Wiki page, you can access a summary of the provided tutorial. For detailed instructions, please visit the provided URL.
In order to use Maven for creating a sample project, it is necessary to have its precompiled package installed on your local machine. Furthermore, you need to make sure you have an OS-compatible Java JDK installed locally. You may access Maven from https://maven.apache.org/download.cgi and a suitable Java JDK from https://www.oracle.com/java/technologies/javase-downloads.html.
Creating a software product includes various steps such as handling dependencies, a compilation of source codes, packaging binary code into artifacts of various kinds and finally deploying those artifacts, locally or into a server. Although a developer may decide to carry out all of these stages manually, s/he may also choose to use a tool for automating them. The benefit of using such an automation tool is to reduce build errors as it helps the developer to focus on code construction independently. Apache Maven is a well-known tool, used for this purpose.
Using a Project Object Model (POM), a developer can configure a Maven project. For doing so, based on the project description, its dependencies and modules' structure, different identifiers are added and removed from the project’s pom.xml file.
-
<groupId>: Unique base name of the project’s developer company -
<artifactId>: Unique name of the project -
<version>: The version of the project -
<packaging>: The method for packaging the produced artifacts: e.g. JAR/ ZIP/ WAR
Using <dependencies>/<dependency> coordinates, it is possible to declare an external library that the Maven project is dependent on.
Each one of these dependencies is uniquely identified with their own unique identifier, i.e. <groupId>, <artifactId> and <version>.
These dependencies are stored locally within a specific repository. Moreover, plug-ins and created artifacts are also stored within the mentioned repo. If necessary dependencies are already available within the local repo, they would be used to complete the build cycle; otherwise, Maven would download and then store them within its local repository.
Using the identifier <properties>, it is possible to access:
. Version of the project’s dependencies
. Build path variables
This section plays a critical role within the POM as it includes information on:
-
Default Maven goal:
<defaultGoal> -
Directory containing compiled artifacts :
<directory> -
Application(packaged artifacts) filename :
<fileName>: ${artifactId}-${version}
Maven has different lifecycles including: . Compile . Package . Unit and integration tests . Install . Deploy
Now, we are going to create a Maven project. For exact instructions, please use the URL provided at the top of this Wiki page. We would follow the steps outlined in section 5. However, you may find a summary of the steps here.
-
Generating a simple "Hello World" project using Maven generate archetype
mvn archetype:generate

-
Compiling the project.
mvn compile

-
Packaging the project.
mvn package

-
Executing the project.
java -cp [SNAPSHOT of the APP] [Main class]

In this tutorial we would become familiar with the theoretical basis of Gradle. Future tutorials would contain hands-on practice for the framework. Such as Maven, Gradle is also a build framework, helping developers to automate their build different tasks. Using a "build.gradle" file, a developer may add various plugins and dependency libraries to configure their build. Furthermore, through adding tasks such as compile and jar, for packaging, and also specifying the main class of the application within the build.gradle, it is possible to use gradle for executing different build stages.