Resolve maven dependencies from JFrog artifactory by configuration in pom.xml - maven

I need to point Maven to JFrog artifactory ONLY to resolve dependencies and not to deploy. For this I'm not allowed to use settings.xml.
I found artifactory-maven-plugin]1 but it show only how to deploy. The main issue that I need to set username/password to access JFrog and also setup Virtual Repos to resolve artifacts and plugins.
And thoughts how to this without settings.xml via pom.xml? Creds I can add to env variables.

You can add a <repositories> section to your POM. It will not override your <distributionManagement> (for deployment). Whether it will actually work depends on the mirror settings in the settings.xml.
Actually, I find it strange that you do not want to change the settings.xml. If you are not responsible for the settings.xml, you can talk to the relevant manager. You could also ask if the relevant repository is added to the company repository as proxy (if you have such a thing).

Related

Is it possible to use different repositories for resolution and deployment in Maven?

Is it possible to get the dependency artifacts from one Repository (PROD) and push the maven build output to another Repository (TEST)?
If YES, then what should be the configuration of POM and other settings?
Pic:
Welcome, Nigam!
Of course, it's possible. In Maven, you configure the repositories you get the dependencies from in settings.xml <repositories> element - here are the instructions. You can specify any number of repositories there.
For deployment you use the <distributionManagement> element of your pom.xml and it can contain a repository different from ones you use for dependency resolution. Here's the official documentation.
If you use JFrog Artifactory (as the tag suggests), you can click on the Set Me Up button on any Maven repository and get the instructions on configuring Artifactory repositories for resolution and deployment.

Maven internal Repository

I have internal nexus repository. I want to install plugins from internal repository, having the dependencies which I want to download from the central maven repository. I am new to maven and really struggling to do the required configuration.
Once you deployed your own plugins into a nexus repository (say "releases") add that repository into the Nexus Group that contains both maven central and your releases repository. Usually developers will only use one url (mirror configured in settings.xml) from nexus and deploy artifacts into a specific repository.
In addition you need to make sure to add the maven group id of your plugins into settings.xml in the pluginGroups section: https://maven.apache.org/settings.html#Plugin_Groups
That should already work.

Divert to locally stored maven-install-plugin

I tried to upload a Windows build to Nexus with the Maven Commandline:
mvn deploy:deploy-file -Durl=http://unity.apps.company.net/nexus/content/repositories/idesktopbuildimages-releases/ -DrepositoryId=idesktopbuildimages-releases -DgroupId=images.WINDOWS7X64EnterpriseSP0unattendedcapture.sources -DartifactId=install -Dversion=6.4 -Dpackaging=wim -Dfile=install.wim
And got the error:
Downloading:
http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
[WARNING] Failed to retrieve plugin descriptor for
org.apache.maven.plugins:maven-clean-plugin:2.4.1: Plugin
org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its
dependencies could not be resolved: Failed to read artifact descriptor
for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
This happens because I don't have Internet access (only Intranet access).
So is there the possibility to divert to a locally stored maven-install-plugin file in my Maven Command?
PS: I tried -DpomFile but got the same output.
Solution:
Adding the Proxy settings to my settings.xml
If you don't have internet access, I assume you have a mirror of maven central available on your intranet. If it's the case you must configure your settings.xml to declare the mirror. So add something like that in your settings.xml file:
<mirrors>
<mirror>
<id>central-mirror</id>
<name>Local mirror of central repo</name>
<url>http://unity.apps.company.net/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
EDIT
Other thing to look at : you may need to configure some proxy settings (it seems strange that they aren't already there...)
see this
You have to set up your settings file to access the public group of Nexus as described in the Nexus book and ensure that your Nexus server has access to Central.
The url for the public group should be .../nexus/content/groups/public. This default group has the "Central" repository in it.
If you are using a different group like your "releases" you should ensure that the Central repository (or Maven Central in older Nexus releases) is part of the list of ordered group repositories as visible at http://books.sonatype.com/nexus-book/reference/confignx-sect-managing-groups.html#fig-group-config
Once that is set you can confirm that the Central repository is reachable by checking out the the proxy repository Central itself in the repositories view and confirm that you can access the remote repo by using the "Browse Remote" tab visible in http://books.sonatype.com/nexus-book/reference/confignx-sect-manage-repo.html#fig-repo-config
If this browsing does not work you Nexus server is most likely blocked by an internal proxy server. If that is the case you have to configure it in Administration - Server - Default HTTP Proxy Settings.

How can I get Nexus to grab artifact files in proxy repositories?

My setup is that I have a local Maven repository on my machine, and one on my team's machine that's managed by Nexus. I added a new proxy repository to Nexus. When I select this new proxy repository and hit "Browse Remote", I see everything (all the JARs, POM files, etc.) in the repository, as it should be. But when I click "Browse Storage", I see almost nothing ... only a handful of POM files, and none of the JAR files.
My Maven build is failing, presumably because it can't get the JAR files from Nexus (the JARs don't appear in my local repository, either, but the POMs do). The other virtual repositories on my Nexus all have the JAR files in storage and in my local repository; how can I get Nexus to grab the JAR artifacts from the remote repository?
I'm sure this is something basic, but I've searched and didn't come up with anything I can use. Thank you!
Enable remote repository index download, add the repository to the public group, make sure that Maven hits Nexus and most importantly read the free book about Nexus.
Here is the chapter about configuring Maven to work with Nexus.
Oh and for proxy repositories it will only download remote artifacts if they are needed e.g. by a Maven build accessing Nexus..
I just ran into this issue as well and thought it might help to have another answer.
I have my repository location at: http://serverName.company.com/nexus-2.3 and I copied/pasted that URL into my settings.xml file. That nexus server points to another company's nexus server so that we only have to point to one to pull down our stuff as well as theirs. Unfortunately, I wasn't able to do that.
That is, until I found out that you have to use the following URL instead of the one above:
http://serverName.company.com/nexus-2.3/content/groups/public/
The snippet of my settings.xml looks like:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://serverName.company.com/nexus-2.3/content/groups/public/</url>
</mirror>
I spent far too long figuring this out. I hope this helps someone in the future.

Why does Nexus repository doesn't download the required artifacts when using a group repository?

I use Nexus repository manager and configured the default .../nexus/content/groups/public/ repository and added maven central, codehaus snapshot and an internal respository that I created and have uploaded few artifacts to that.
Then added .../nexus/content/groups/public to mirror in settings.xml. When I do a maven build, maven looks in .../nexus/content/groups/public but does not update org.apache.maven.plugins:maven-site-plugin:pom:2.0-beta-6 and reports that it is not found.
But if I remove the mirror from settings.xml, then it looks in http://repo1.maven.org/maven2/ and it picks up all the artifacts correctly.
I have also changed publish url to true. What do I miss?
If you added the repositories as proxy repositories in Nexus do not forget to add the proxies to the Repository Group which you use as mirror for all Nexus requests (public/snapshot) - assumed you have this kind of configuration.

Resources