How to download selective dependencies using Maven from JFrog Artifactory? - maven

I have a simple Maven project and its pom.xml has some dependencies to some local jar files inside the project structure. Now I want to upload those local jar files in JFrog Artifactory and change the pom in such a way so as to use selective dependencies from Artifactory and rest of the Pom files remains the same like it was(which includes some spring boot, Junit, surefire dependencies etc etc). How can I alter the pom file so that I can selectively download those jars from Artifactory rather than from my local machine.
I uploaded the local jars in a folder in Artifactory but unable to configure my pom/maven to download those during clean install. I tried as per the documentation in Jfrog to modify the settings.xml and include the server tag and aslo added distribution management in pom.xl to refer to the Jfrog Artifactory. But this is for all the dependencies no? I want selective dependencies to be downloaded from Artifactory.

Related

Maven artifact not uploaded with pom file

I have a backend multimodule maven project, that is build on jenkins with mvn clean package command (maven version 3.3). After a sucessfull build I upload two of the maven subprojects target/*.jar to private nexus (using Nexus artifact uploader plugin). The jars from target folders are uploaded correctly, but the pom is not (there is no option in the plugin to upload the pom).
Then I have my webapp project, where I have dependency to the two artifacts on my private nexus. They are found and downloaded, but not the pom. Building the webapp project fails, because the dependencies are not resolved for the two jars. A warning is printed out during build:
[WARNING] The POM for <groupId>:<submodule-artifactId>:jar:1.0.0 is missing, no dependency information available
That is reasonable - I can clearly see in nexus repository that it has only jar, md5 and sha files. How should I build my multimodule maven project in a way I would be able to reference only submodules in my webapp project? Or should I upload the submodule projects poms manualy?
I am open to upload the whole backend project to nexus, but I would like to be able to add only subprojects as dependencies to my webapp.
Since you are using a private nexus, you need to specify in your maven where to look for your artifact. Usually the way to do it is to specify a repository configuration in your pom.xml as specified in this link. This will tell maven to contact your private nexus for your artifacts.

Maven pom to zip config files from GitHub and jars from artifactory

Requirement:
Need to push config files and jars from artifactory to UCD for deployment.
Config files are present in GitHub repostiory.
Jars (not needed for build but needed to start application in UCD) are present in artifactory.
What would be the general process to follow, in order to copy config files from github and download/copy jars from artifactory and package everything in a zip file to push to UCD?
You might consider:
the maven download plugin to get the files you need from an URL (like a GitHub repository or an Artifactory one)
the maven assembly plugin to build your archive
configuring on UCD side the source of your Nexus package to deploy, although there is a urbancode plugin maven-ibmucd which could be handy (not tested)

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.

How to install a Maven/Gradle project along with all its dependencies to a local repository?

I have a Gradle project that depends on several open-source projects up on Maven Central. I'd like to install the project – along with all its direct and transitive dependencies – to my local maven repository, so that I could later zip it all up and put it on offline machines.
How do I do it with Gradle/Maven?
mvn dependency:get plugin will fetch the artifact with all dependencies to the local repository.
I had also developed a plugin to install remote artifacts to a local machine.
If you want to later ZIP up your project w/ dependencies and move them to a different machine, you could try Maven's appassembler plugin. It collects all dependencies and creates a launcher, all in the target folder, ready for deployment.
But note, this, by default, creates a flat directory structure with all dependencies, it doesn't preserve the Maven format. It also has the option to create a 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