Download files from nexus repository - maven

How to download files from nexus server ? (Is it for only Maven plugins repository or We can store any dependencies of my project)

You can use maven plugin :
mvn org.apache.maven.plugins:maven-dependency-plugin:2.6:get -DreadmoteRepositories=http://nexus.mydomain.com/nexus/content/repositories/snapshots -Dartifact=com.mydomain.myproject:myproject:1.0.0-SNAPSHOT:jar -Ddest=myfile.jar
OR, you can use REST API if you want : https://maven.java.net/nexus-core-documentation-plugin/core/docs/rest.artifact.maven.redirect.html

nexus per artifact has multiple files (metadata, pom.xml, source, javadoc, jar, etc..), you can download them and use separately in your own project, but that doesn't sounds like very good idea when you have maven todo this for you in managed way

Related

tell maven to get JAR dependency from given URL

Unfortunately, my project has an external dependency that was never published to any Maven repository. The only way I can get it is by direct download from github (they pushed the binary to github).
One (bad) way is to download the jar manually and commit/push it to my code repository (git). It wouldn't help me to manually deploy this artifact in my local binary repository because I share this project with external contributors that cannot access my private binary repo.
I wonder if maven has a better way to handle this? (Given that I can't upload the artifact to my repo or public repo).
I know that npm allows getting some dependencies from URL. Does maven support it as well?
AFAIK there is no nice way to handle this. You could
Write a script that downloads the jar and installs it in your local Maven repository. This script could be shared through your code repository.
Include downloading and installing the artifact into the Maven build process (by writing a Maven plugin or using the antrun plugin)
Set up a nexus in the cloud that everyone in your team can access.

Backup Maven dependencies to repository

I am frequently using maven artifacts as dependencies from external repositories which go (permanently) offline surprisingly often. I'd like to save all dependencies a given project has and save them in a local repository - just like using maven deploy -DaltDeploymentRepository=... for a single project. This repository should then be usable like any other maven repo when put on an HTTP server.
I tried using mvn dependency:copy-dependencies -Dmdep.useRepositoryLayout=true, but it does not create files like maven-metadata.xml or copy .pom files.
I do not want to use any repository managers like Artifactory, I just have a static file server.
Thanks in advance.

Publish dependencies of an artifact with Gradle

I'm looking for a way with Gradle to generate a maven repository with all dependencies and transitive dependencies.
For example, my project can depend on hibernate. I'd like to create a local repository somewhere on the disk with hibernate and its own dependencies.
I tryed several ways but no success:
uploadArtifact: it seems not possible to upload dependencies of the artifact
Sync task: I don't have maven metadata and I loose transitive dependencies
The context:
My product has an engine and a webapp and could deployed as a War archive, an EAR archive or without the webapp, with or without some components in them. I need to provide users a way to configure what they need and a script to generate it. Gradle seems a good candidate but I don't see how to create a local repository with all dependencies that may be needed.
Does anyone see a solution ?
Thank you
There isn't currently an easy way to achieve this with Gradle; you'll have to script your own solution. In particular, you'll have to find a way to recreate the original POM when publishing the archive.
I found a solution which may be used by others.
The idea: use maven to generate the repository and package the project as a zip using the assembly plugin.
I fake maven with :
<repositories>
<repository>
<id>my-internal-site</id>
<url>file://${user.home}/.m2/repository</url>
</repository>
</repositories>
and call it like it :
mvn install -Dmaven.repo.local=./src/lib/
The pom will contain main dependencies and src dir everything else to include in the "bundle"

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.

Publishing artifacts with sources on archiva

At work I'm dipping my toes in managing project dependencies with maven. We use Apache Archiva (1.2.1) as a local repository and proxy. I'm adding artifact for open source project, that is not published on any public repository. I've learned that to publish the sources I should use the Classifier field on Upload artifact page. The sources are then listed alongside the jar and pom when I browse the repository.
But when I update my maven dependencies I get only the jar and pom from the repository. I noticed that sources are also missing when the archiva proxies for me the downloads from other public repositories. I didn't find any configuration options in Archiva's admin pages to serve the sources... What am I missing?
Update: I was missing the fact that artifact sources have to be downloaded manually. I.e. the maven client has to request them, which is controlled by command line option -DdownloadSources=true. Maven Integration for Eclipse has a preference setting to always download them as described in Resolving artifact sources. Archiva then serves the sources for local artifacts or proxies the request to remote repositories and caches the sources for future requests.
Archiva does serve the sources, but Maven does not request them by default. I know since I also use Archiva as my Maven repo. How are you requesting the sources?
If you're using eclipse
you can run mvn eclipse:eclipe -DdownloadSources=true in the project directory;
you can install the Maven Integration for Eclipse.
Both of them should return the sources if they are available.
The sources aren't required to satisfy compile/runtime dependencies. If you wanted to bundle sources with your app, then you would specify a dependency with a source. Or you would use a plug in like assembly to grab them from archiva.

Resources