Can I have multiple local repository for maven? - maven

In maven settings, there is an entity which refers the local repository:
<localRepository>~/.m2/repository</localRepository>
When I add another one, like this:
<localRepository>~/another/place</localRepository>
it raises Duplicated tag error.
Can I have multiple local repository or maybe add another direcotry to the local repository?
EDIT
This idea seems a possible answer, too:
mvn -Dmaven.repo.local=/path/to/repo

Yes you can have and you can do it in your POM.xml itself. Below is an example.
<project>
...
<repositories>
<repository>
<id>firstrepo</id>
<name>repo</name>
<url>http://myrepo.my</url>
</repository>
<repository>
<id>secondrepo</id>
<name>repo2</name>
<url>http://myrepo.yours</url>
</repository>
</repositories>
...
</project>
Second Method by creating profile in your settings.xml
For multiple local repositories you can have multiple settings.xml file.
In the command line specify alternate path using
mvn -Dmaven.repo.local=/path/to/repo For more information you can check this link. Hope it helps.

Related

How to set global maven distrubution management settings?

I want to avoid putting this part in pom.xml of every project distributed the same way
<distributionManagement>
<repository>
<id>my-id</id>
<name>My deployed artifacts</name>
<url>https://organization.xxx/maven/</url>
</repository>
</distributionManagement>
How to set it globally via maven command or editing setting file?
Cannot be done in settings.xml.
What you can do:
Use a company parent POM that specifies the distributionManagement.
Set a property in the settings.xml and use it in distributionManagement.
Use -DaltDeploymentRepository=... on command line for the build. See also https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html#altDeploymentRepository

Maven:Including jars from remote repository

I wish to include jars present under \10.171.98.23 system [ex:\10.171.98.23\workspace\Project\lib] in my pom.xml by making use of remote repository concept.
How it could be achieved in Maven?Any suggestions would be more useful to proceed
The simplest example would be:
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://myserver/repo</url>
</repository>
</repositories>
Check the documentation for more détails. You could also have a look at Maven the reference guide.

Maven Tycho: Cannot add artifact descriptor which has not been created by this repository

I'm trying to build an RCP application via Tycho and I receive this error when exporting the product.
I don't really understand the issue, but could it be that the reason why it fails it's because I'm using multiple P2 repositories to retrieve my plugins dependencies?
This is the snipped of the repositories I've defined in my parent POM. The rest is pretty standard Tycho.
<repositories>
<repository>
<id>eclipse-luna</id>
<url>${eclipseLuna}</url>
<layout>p2</layout>
</repository>
<repository>
<id>systems-rc-p2</id>
<url>${systemsRcP2}</url>
<layout>p2</layout>
</repository>
<repository>
<id>systems-snapshots-p2</id>
<url>${systemsSnapshotsP2}</url>
<layout>p2</layout>
</repository>
</repositories>
I found the issue.
Basically for some reason (project needs) I had to change the "sourceDirectory" and the "outputDirectory" of the project, pointing them to the classic "src" and "bin" instead of the Maven default "src/main" and "target".
In particular, what was causing the issue was the redefinition of the <outputDirectory> property and the <directory> one. It looks like Tycho does not like it at all.

Parent pom not resolvable unless I add repo to child pom - conundrum

I want to include a parent in a project pom, containing distribution management and repositories. As one would expect.
When I mvn package the child, maven is unable to resolve the parent pom, unsurprisingly.
I can make it resolve the parent by adding my internal nexus repository to the child pom. But this sounds like eggs laying chickens - I'm telling the child something it should know from the parent. I would have to add this repo to every child pom that has a parent.
How can I avoid this?
As khmarbaise wrote, you need to define your repositories in a profile in your settings.xml (this seems somewhat weird, but is actually the only feasible way):
<profiles>
<profile>
<id>repos</id>
<repositories>
<repository>
<id>my-local-repo</id>
<name>Projektserver Snapshots</name>
<url>http://my-server/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>repos</activeProfile>
</activeProfiles>
Depending on your actual config, you would also include mirror setting and might call your local nexus central.
Sounds like the parent has been deployed to your internal nexus repository so it picks it up from there once you add in the distribution management and repository details.
To make it pick it up from your local copy. First ensure the versions match. Then navigate to the parent and run mvn clean install. This will push the parent pom to your local maven repo.
You may also get round this by ensuring you have added the releativePath element to the parent details in the child pom, you may not need to manually build the parent then but im not 100% sure and havent tested that.
The only things which should defined in your pom is distributionManagement the repositories should be defined in settings.xml instead.

Maven: adding dependency not present in the mirror

We are using a local nexus mirror for all of our dependencies.
I need the following dependency in one of the projects:
<depedency>
<groupId>com.smartgwt</groupId>
<artifactId>smartgwt</artifactId>
<version>3.0</version>
</depedency>
from the repository: http://www.smartclient.com/maven2
But maven is giving me error saying that "Failure to find com.smartgwt:smartgwt:jar:3.0".
What might be the problem and how can I solve it?
(Maybe this is very trivial question but I am fairly new to Maven)
I'm assuming Nexus is working for all your standard dependencies hosted on Maven Central.
You can work out where Maven is downloading from by turning on debugging with the -X parameter when doing a build. There will be a lot of noise but if you look a few lines above where your build fails because of failing to find the dependency, it will tell you:
where it is trying to download the dependency
whether it is using a mirror
if there are any HTTP error codes when downloading
How is http://www.smartclient.com/maven2 set up in your Nexus proxy? As a separate proxy repository? Can Nexus access this repo (is it 'In Service' and not blocked)?
Is this repository in Nexus added to the 'public' group? If you don't want this then:
You have to configure a separate mirror in your settings.xml for this repository which points to the URL in Nexus.
Also check that you have added the repository in your POM, e.g.
<project>
...
<repositories>
<repository>
<id>smartclient</id>
<name>SmartClient Maven Repository</name>
<url>http://www.smartclient.com/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
...
</project>
And then configure a proxy entry in your settings.xml for this repository:
<settings>
...
<mirrors>
<mirror>
<id>smartclient-nexus-proxy</id>
<mirrorOf>smartclient</mirrorOf>
<url><url of your smartclient proxy repository in Nexus></url>
</mirror>
...

Resources