This repository is a tutorial on how to create, deploy to the remote repository and then use a custom parent POM with the help of Repsy (https://repsy.io/).
To complete the tutorial you need the latest versions of:
- Linux Ubuntu
- Java Development Kit
- Maven
Firstly you need to configure your Repsy repository to be able to push there your parent POM.
- Create an account at https://repsy.io/
- Log in to your Repsy account
- Go to https://repsy.io/
- Go to the 'Maven' tab.
- Create a new Repsy repository by providing a name for it (e.g. parentpom) and clicking a plus sign (Add new repository)
- Configure your
~/.m2/settings.xml
at your home directory according to the example below. By default, the~/.m2/settings.xml
file doesn't exist. In such a case you need to create it. Besides that, don't forget to remove ellipsis (...
) from the example below and provide your ownusername
andpassword
:
<settings>
...
<servers>
...
<server>
<id>repsy</id>
<username>ciechanowiec</username>
<password>PASSWORD</password>
</server>
...
</servers>
...
</settings>
Secondly you need to create a parent POM that will be deployed to the Repsy repository and used in child projects. You can find an example of a full parent POM in this project's root folder (see pom.xml
file).
- A parent POM should have
<packaging>
of typepom
(the last line in the listing below):
<groupId>eu.ciechanowiec</groupId>
<artifactId>parentpom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
- Dependencies declared in a
<dependencies>
section in a parent POM will be imported to the child projects' POMs. It means that those dependencies can be directly used in child projects, without declaring them in child projects' POMs:
<dependencies>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>${tinylog-api.version}</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<version>${tinylog-impl.version}</version>
</dependency>
</dependencies>
- Dependencies declared in a
<dependencyManagement>
section in a parent POM will not be imported to the child projects' POMs. It means that in order to use those dependencies in the child projects, the dependencies should be declared in child projects' POMs. However, simultaneous declaration of those dependencies in the<dependencyManagement>
section in the parent POM helps to unify versions of the dependencies used in all child projects' POMs:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Due to the above <dependencyManagement>
section there is no need in specifying the version of the dependency in child projects' POMs.
- To be able to deploy a parent POM to the Repsy repository, it is needed to specify that repository in the
<distributionManagement>
section of the POM according to the example below. For the<name>
section any value can be defined and the<url>
section should point to the Repsy repository:
<distributionManagement>
<repository>
<id>repsy</id>
<name>Repsy Repository</name>
<url>https://repo.repsy.io/mvn/ciechanowiec/parentpom</url>
</repository>
</distributionManagement>
Thirdly you need to deploy a parent POM to the Repsy repository. Do it by executing the following command:
mvn compile deploy
Fourthly you need to configure a child POM in an appropriate way. You can find an example of a full child POM in this project's root folder (see childpom.xml
file).
- Define in a child POM the parent POM:
<parent>
<groupId>eu.ciechanowiec</groupId>
<artifactId>parentpom</artifactId>
<version>1.0</version>
</parent>
- Define in a child POM the Repsy repository in which the parent POM is stored:
<repositories>
<repository>
<id>repsy</id>
<name>Repsy Repository</name>
<url>https://repo.repsy.io/mvn/ciechanowiec/parentpom</url>
</repository>
</repositories>