Simple way how to use gitlab for a private maven repository.
Open your pom.xml
and add repository information. For this example I used maven
branch in project for maven repository.
1 2 3 4 5 6 |
<repositories> <repository> <id>gitlab.com.username.example-lib</id> <url>https://gitlab.com/username/example-lib/raw/maven/</url> </repository> </repositories> |
add maven-deploy-plugin
:
1 2 3 4 5 6 7 |
<plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <configuration> <altDeploymentRepository>internal.repo::default::file://${project.basedir}/../${project.name}-mvn-repo</altDeploymentRepository> </configuration> </plugin> |
Assembled project will be saved next to your project in a folder named “${project.name}-mvn-repo
”
Full pom.xml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<?xml version="1.0" encoding="UTF-8"?> <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.ubs_soft.basurlakh</groupId> <artifactId>example-lib</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <repository> <id>gitlab.com.basurlakh.example-lib</id> <url>https://gitlab.com/basurlakh/example-lib/raw/maven/</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <configuration> <altDeploymentRepository>internal.repo::default::file://${project.basedir}/../${project.name}-mvn-repo</altDeploymentRepository> </configuration> </plugin> </plugins> </build> </project> |
Now run in console “mvn deploy
”
or in Idea:
Now go to generated folder “${project.name}-mvn-repo
”
1 2 3 4 5 6 |
git init git checkout -b maven git add . git commit -m "realise 1.0" git remote add origin git@gitlab.com:basurlakh/example-lib.git git push origin maven |
Configure maven to use the repository.
Create or open in home directory .m2/settings.xml
. To access gitlab we need to add http header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <id>gitlab.com.basurlakh.example-lib</id> <configuration> <httpHeaders> <property> <name>PRIVATE-TOKEN</name> <value>xxxxxxxxxxxxxx</value> </property> </httpHeaders> </configuration> </server> </servers> </settings> |
you can get private token in this page https://gitlab.com/profile/account
Now, in another project, you can include your library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?xml version="1.0" encoding="UTF-8"?> <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.ubs_soft.basurlakh</groupId> <artifactId>example-use-custom-maven</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <repository> <id>gitlab.com.basurlakh.example-lib</id> <url>https://gitlab.com/basurlakh/example-lib/raw/maven/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.ubs_soft.basurlakh</groupId> <artifactId>example-lib</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project> |