27
loading...
This website collects cookies to deliver better user experience
pom.xml
file. However, there's much more to Maven than meets the eye and you can very quickly get lost in a sea of knowledge. This article will aim to walk you through the important concepts in Maven and introduce you to various terminologies in the Maven ecosystem.package.json
file in node projects, composer.json
file in php projects, requirements.txt
in python projects and build.gradle
in other Java/Kotlin projects, the POM file should seem familiar.mvn -B archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
my-app
has been created for the new project, and this directory contains a file named pom.xml
that should look like this:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
... lots of helpful plugins
</pluginManagement>
</build>
</project>
pom.xml
contains the Project Object Model (POM) for this project. The POM is the most basic unit of work in Maven. This is important to remember because Maven is inherently project-centric in that everything revolves around the notion of a project. In short, the POM contains every important piece of information about your project and is the go-to place for finding anything related to your project.project This is the top-level element in all Maven pom.xml
files.
modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins
is the designated groupId for all Maven plugins.
artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form -. (for example, myapp-1.0.jar
).
version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see a SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
name - This element indicates the display name used for the project. This is often used in Maven's generated documentation.
url This element indicates where the project's site can be found. This is often used in Maven's generated documentation.
properties This element contains value placeholders accessible anywhere within a POM.
dependencies This element's children list the dependencies. The cornerstone of the POM.
build This element handles things like declaring your project's directory structure and managing plugins.
sdk-for-android-0.0.1-javadoc.jar 2021-06-29 15:13 261
sdk-for-android-0.0.1-sources.jar 2021-06-29 15:13 18663
sdk-for-android-0.0.1.aar 2021-06-29 15:13 46437
sdk-for-android-0.0.1.pom 2021-06-29 15:13 3277
.md5
, .sha1
, .sha256
, .sha512
and .asc
files which are all used by Maven Central and other consumers for verifying the signature and authenticity of your artifacts.<artifactId>-<version>-<classifier>.<extension>
Note : classifier is an optional field and is absent in the case of Primary Artifacts which in the case of our Android project are the aar and pom files.
aar
file can contain Android resources and a Manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to all the Java classes and methods. Our pom
file contains information about our library including all the dependencies we use internally. <dependencies>
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>0.0.1</version>
</dependency>
/$groupId[0]/../${groupId[n]/$artifactId/$version/$artifactId-$version.$extension
<groupId>
element in the pom file as follows $groupId is a array of strings made by splitting the groupId’s on “.” into directories.
org.example.subdomain
, our $groupId
array would be [org, example, subdomain]
, which when translated into directories, becomes org/example/subdomain
. io.appwrite
is translated to the following path io/appwrite/
.pom.xml
file listing its main dependencies, those dependencies also have a remote pom
file serving a similar purpose. Maven uses this file to figure out what other dependencies to download. When a coordinate does not contain a <classifier>
, it is considered a primary artifact and is expected to have a pom available..pom
file and the .aar
file.io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.pom
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.aar
javadocs
and/or sources
for a particular dependency. However, unlike a primary artifact, a secondary artifact is not expected to have a remote pom
and thus never has any dependencies.<dependencies>
section just like primary artifacts:<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>0.0.1</version>
<classifier>sources</classifier>
</dependency>
$classifier
variable./$groupId[0]/../$groupId[n]/$artifactId/$version/$artifactId-$version-$classifier.$extension
javadocs
and the sources
.javadoc
file for Appwrite's Android SDK can be located at
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1-javadoc.jar
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1-sources.jar
md5
, sha1
, sha256
and sha512
checksum for that artifact and compares it to the values found in the checksum files located at $ARTIFACT_URL.md5, or $ARTIFACT_URL.sha1, respectively.This is strictly meant as a way to quickly verify downloads, and it is NOT meant to be used for authentication or security purposes. This is also NOT a substitute for using HTTPS, as checksums can be trivially intercepted and modified along with the modified artifacts.
sha1
checksum for our aar artifacts for example, would be present at
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.aar.sha1
md5
checksum for our aar artifacts for example, would be present at
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.aar.md5
.asc
file that contains the signature of the author of the artifact. $artifacts.asc
For our .aar
file for example, the corresponding .asc
file would be located at
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.aar.asc
$checksum.asc
For our .md5
( sha1, sha256 etc.) files, the corresponding .asc
file would be located at
io/appwrite/sdk-for-android/0.0.1/sdk-for-android-0.0.1.aar.md5.asc
Local
The local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released. This is usually located in $HOME/.m2/repository
Remote
Remote repositories refer to any other type of repository, accessed by a variety of protocols such as file:// and https://. These repositories might be a truly remote repository set up by a third party to provide their artifacts for downloading (for example, repo.maven.apache.org). Other remote repositories may be internal repositories set up on a file or HTTP server within your company, used to share private artifacts between development teams and for releases.
0.0.1
of your library, you must not modify the existing version, instead publish the next version let's say 0.0.2
. This is enforced by default in Maven Central.