I want to publish my maven project to a local directory but not in $HOME/.m2/repository
. I have created the following directory structure:
$HOME/myrepo
|- third_party
- private
The directory $HOME/myrepo/third_party
holds, as the name suggests, external artifacts from 3rd parties. I want to publish my own projects into $HOME/myrepo/private
. Therefore, I use the following adjusted $HOME/.m2/settings.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven-private</id>
<username></username>
<password></password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-local</id>
<url>file:///home/user/myrepo/third_party</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
The file pom.xml
for my test project looks 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</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>maven-private</id>
<name>Internal Release Repository</name>
<url>file:///home/user/myrepo/private</url>
</repository>
</distributionManagement>
</project>
When I run
mvn install
The project compiles successfully and all required files are fetched from $HOME/myrepo/third_party
, however, after compilation the project is always installed to $HOME/.m2/repository
.
How do I have to configure maven in order to publish my projects into the $HOME/myrepo/private
directory?
CodePudding user response:
If you want to put the artifacts in a repository other than local, you are not thinking of installing but deploying them. Installing with maven by definition puts the artifacts in local repository - so unless you intend to overwrite the location of .m2/repository
and all its contents, just run
mvn deploy
CodePudding user response:
You can change the location of your local Maven repository, i.e. where artifacts are installed, by editing the Maven settings file ~/.m2/settings.xml
. Specifically, you are interested in changing the <localRepository>
to directory of your choice. One thing to look out for is that path you specify must be an absolute path according to the Configuring your Local Repository section of the user guide. Please also note that this will affect all artifacts (both your private and 3rd party ones) as Maven only supports a single local repository.
Example:
<settings>
<!-- settings -->
<localRepository>/path/to/local/repo/</localRepository>
<!-- more settings -->
</settings>