How to deploy maven parent pom.xml into artifactory? - maven

I created a pom.xml which contains my general dependencies. I want to add this pom into our inhouse repository (Artifactory) and then want to use it in all of my maven modules pom files as defining .
I can install the parent pom.xml into M2 and use it successfully but after I deployed the parent pom into Artifactory other poms can't download parent pom from Artifactory. I am sure that my inhouse repository settings are correct in settings.xml.
Is there a success way for this purpose?
Thanks in advance...

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.

How can I link other maven pom?

I'm trying to use mvn install, but of course I get error (The POM for projectA:jar:1.0.0-SNAPSHOT is missing, no dependency information available)
How can I link pom for it into this command?
Maven resolves POMs and other artifacts through the local repository and the repositories given in the settings.xml in your .m2 directory. You do not need to "link" POMs explicitly.

Why there is a pom.xml for all jars in mave repository

In the maven repository, there is a pom.xml corresponding to every jar. What is the use of that pom.xml.
How important is that pom.xml and will the execution work without that pom.xml ? Thanks in advance.
Each of those jars is a project (somewhere) that was built using Maven - hence the need for a pom. Also, the pom describes all the transitive dependencies for any jar that your project needs. Those files are important, and your project cannot build without them.

Artifactory, Maven and a project with several modules

I have a Maven project with several modules, with a structure similar to:
project
module-1
pom.xml
module-2
pom.xml
..
module-N
pom.xml
pom.xml
I have defined the Artifactory Maven plugin in the parent pom.xml which is under project, like it is done in the examples they offer on their website and I've also tried the example they have in git.
My problem is that I don't want to publish to Artifactory all the artifacts generated by the parent pom, but only those under certain modules, so I tried defining the plugin in the parent pom with the tag <publishArtifacts>false</publishArtifacts> and then defining the plugin again on the modules which contain artifacts I really do want to deploy with <publishArtifacts>true</publishArtifacts>, however no artifact is deployed.
If I try the other way, only specifying I do not want to publish Artifacts on the modules I don't, it does deploy all ignoring that configuration.
How should this be done using this plugin?
You can use the publisher\excludePatterns in the artifactory plugin section of the pom.xml to exclude artifacts from being published.
you can declare multiple patterns with wildcards, and separate each with a comma.
For example, if you are using the sample from
"https://github.com/JFrogDev/project-examples/tree/master/artifactory-maven-plugin-example"
then, setting you're pom with
<excludePatterns>multi3*.war,multi2*.jar</excludePatterns>
would exclude those files from being published to Artifactory.
hope that helps...

How do I add an artifact to a local maven repository so that it will properly reference its own set of dependencies?

I am developing an application that depends on a number of legacy JAR files and I want the project to build straight out of version control without other users having to install these JARs in their local repository. I cannot add them to the corporate repository so I have created a repository that is local to this project and I have added these JARs to that repository using maven-install-plugin:install-file and setup the repository entry in the POM file so it knows to search the local repository.
This works exactly the way I want...up to a point. The problem is that most of these legacy JAR files have their own set of dependencies. I would like for them to work just like other artifacts that have their own set of dependencies so that maven can resolve everything and include all the necessary files but I can't find a way to do this with any maven-install-plugin:install-file options (or any other maven commands/plugins). I am pretty new at maven so I am probably just ignorant on this point.
As a work around, I attempted to go into the local repository directory and manually edit the POM file for the artifact to include the dependencies. This didn't cause any errors but it is also not pulling in those dependencies.
Can someone out there give me a clue?
The maven-install-plugin:install-file goal has a pomFile attribute. You can use this to specify a POM file for your legacy jar. You would create a POM file that points to all of the dependencies by artifactId in the <dependencies> section. If you have a remote nexus repository you can use the admin screen for the repository to deploy a jar.
Once you edit POM files in your project specific repository, host it as maven repo using Maven Repository Managers (like sonatype nexus). Add your project nexus repo as one of the maven repo in project pom.xml as below
<repositories>
<repository>
<id>my-project-mvn-repo</id>
<name>my-project-mvn-repo</name>
<url>http://<your project maven repo URL here></url>
</repository>
<repositories>
Now all developers should be able to make build. The legacy jar files POM contains dependency. Maven should take care of automatically pulling dependent jars on developer's workspace.

Resources