How to get Sonatype Nexus to download the latest version of jar? - maven

I'm using Sonatype Nexus 1.5.0 and a particular jar has a newer version in the Public Maven Central while my Nexus doesn't have it.
Assume that only the server where the Nexus is installed has the internet connection and my local laptop is not allowed to connect to internet directly, how to let the Nexus the download the newer version of the jar so that my local build can download the newer version from Nexus?
The settings.xml of my local Maven is configured with the URL of the Nexus to download the jars.
Please advise.

Here is a summary of how your local repository, remote repo (Nexus), and Maven Central work together. If you have requested the new version of the jar in your POM, then it should end up in Nexus and your local artifact repo. If it doesn't, something is not configured correctly, and #khmarbaise gave you some good starting points for troubleshooting in his comment.

Related

is it possible to tell dependabot to not connect to central maven at all

In enterprise environment, the connection to central maven could be blocked. In this case,
i) either don't connect to central maven at all
ii) or if the connection to central maven is not successful, don't raise exception, just move on to other repositories
currently i see below exception
/vendor/ruby/2.6.0/gems/excon-0.76.0/lib/excon/socket.rb:285:in `select_with_timeout': connect_write timeout reached (Excon::Error::Timeout)
so I am wondering if there is any way to tell dependabot to not try connecting to maven central at all.
fyi. i am running https://github.com/dependabot/dependabot-script
Generally what happens in an enterprise environment, it does have the local repository like Nexus within the network. Now you mirror your local nexus repo in settings.xml. You can mirror any no. of repo in your settings.xml. Now, maven first try to find the dependencies in your all local repo first and if it does not find it, only then it goes for maven central repo.
If the maven central is not block, then the library first downloaded to your local nexus repo and then would be downloaded to your local. So next time when you will try to download this library, it will be available in your local enterprise nesus repo.
You can block the maven central repo, refer - https://stackoverflow.com/questions/4997219/disable-maven-central-repository#:~:text=In%20maven's%20home%2C%20in%20the,or%20just%20override%20it's%20definition.
But as per your question, if the dependency library not found in any repo, there would always be an exception in maven build.

How do I get my Nexus repo to download a more recent artifact?

We have a Nexus repository on my local network that is managed by a different team and I use it as a local mirror of Maven-central . My Gradle 1.7 build script is trying to download a set of "Selenium 2.35.0" artifacts from the Nexus server (which is setup as a mirror in my .m2/settings.xml file) but it times out and fails. There are 2.33.0 artifacts on the server though.
Is there a command I can issue from the command line to trigger the Nexus server to cache the latest version of Selenium? OR , is this something the Nexus admin has to do?
Gradle doesn't work with .m2/settings.xml.
You need to define your Nexus in gradle script itself (using repositories{} closure).
Nexus is a caching proxy. It won't download the newer version unless someone asks for the newer version.

How to deploy JAR to Maven remote repository

Is there any way to put my JAR file in remote repository, so my maven project can get this JAR file from any place via Internet?
I have downloaded and did some fixes in the ReportNG project: https://github.com/dwdyer/reportng .
Using ANT I have compiled this project into JAR, now I want to put it into remote Maven repository, but don't know how I can do that.
Could somebody please suggest me the way, how I can perform that?
If it is a released version you want to make available in maven central follow this guide: http://maven.apache.org/guides/mini/guide-central-repository-upload.html
I'm no github professional but since a maven repo is just a file structure with some meta-data you can put it anywhere maven can read it (ftp, http, ...). so you could create a git repo to host your maven artifacts. see http://cemerick.com/2010/08/24/hosting-maven-repos-on-github/ for an example. (it may be outdated - github may have something like maven repo hosting, I just dont know)
A lightweight way to create your own maven repository is to store it on github. See Hosting a Maven repository on github for more details
I followed sonatype open source project maven deployment guide https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide and successfully deployed the latest version of reportNG into maven central repository. Now maven have both 1.1.3 and 1.1.4
http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.uncommons%22%20AND%20a%3A%22reportng%22
You should do a pull request to the github project. If the maintainer likes your fix he will put it in the next version.
If you need your fix in a remote repo NOW then you'll have to setup your own maven repository.

maven could not resolve dependency via my local nexus repository

I have setup an in-house Sonatype Nexus repository and configure the maven to check my local Nexus instead of getting artifacts directly from public repositories.
http://www.sonatype.com/books/nexus-book/reference/config-sect-intro.html
Our project was able to download the most artifacts except one artifact in Maven central.
Here is the build error:
Failed to execute goal on project shindig-gadgets: Could not resolve dependencies for project org.apache.shindig:shindig-gadgets:jar:3.0.0-SNAPSHOT: Could not find artifact com.ibm.icu:icu4j:jar:4.6 in nexus (http://my_nexus_repository:8081/nexus/content/groups/public) -> [Help 1]
I see that icu4j-4.6.jar does exist in the Maven central repository. On my local nexus repository, it doesn't exist. I see only icu4j-4.6.pom exists on my local nexus repository.
It's not like my nexus repository setting is totally broken. maven project has successfully downloaded numerous jar files from multiple public repositories via my local nexus maven repository except icu4j-4.6.jar.
I don't understand why I'm having a problem with only icu4j-4.6.jar. Would it be incorrectly cached on either my local maven or nexus maven repository?
If it was incorrectly cached, how can I clean the local maven or nexus maven repository?
The similar problem is described at
Missing maven dependency using nexus setup
icu4j-4.6.jar does not show up in the search list. Only icu4j-4.6.pom shows up in the search list. I don't think is Snapshot VS Release issue because icu4j-4.6.jar seems release jar.
Is it possible that the nexus repo just stopped responding for a while? You can try mvn -X (or -d?) to get detailed info about what is going on. You might also try configuring an alternative repo.
Perhaps you haven't enabled remote index downloads from Maven Central. This would explain why only the POM file appears in your local search (The only file which has been downloaded via the proxy repo).
There might be another issue causing the download failure for the jar itself.... I suppose try and solve one problem at a time :-)
Try adding -U to your mvn arguments to force an update of your local repository.
You could also have corrupt meta data in the repo. In which case, delete that artifact from the repo's cache and let it refresh.
If the artifact in question was cached in properly from the proxy repository, using mvn -U will fix the problem
However if you are seeing pom on your nexus ,this usually happens when the artifact from the proxy repository is not cached in properly. The way to fix is
1) Browse to the component in the Proxy Repository.
2) Invalidate the cache for the repository and reindex the Nexus repository.
3) run mvn clean -U

Nexus Suggested Repositories

I setup an internal Nexus Maven repo and I had a question about which additional Maven repos I should include from the initial setup. What are some suggested Maven repos? So far I have added JBoss, Apache Releases, and Codehaus Releases.
As far as I know , all of these repos are synced with Central. You can verify this by looking up Apache or JBoss artifacts using the maven central search engine.

Resources