How can I link other maven pom? - maven

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.

Related

How does Maven use external dependencies in your own project?

I had a quick question on how Maven configures dependencies in the pom.xml file. In my project's pom.xml file, when I add a dependency tag and provide the artifact id and group id, how/where does Maven store those dependencies to use in my project? Since Maven is a central repository, does Maven use the internet to pull the dependencies or does it download the repositories in your local machine and use it from there?
Maven repository is of three types :
Local
Central
Remote
Maven first starts finding in Local Repository created by Maven in %USER_HOME% directory. To override the default location, mention another path in Maven settings.xml file available at %M2_HOME%\conf directory.
When Maven does not find any dependency in a local repository, it starts searching in the Central repository.
Sometimes, Maven does not find a mentioned dependency in the central repository as well. It then stops the build process and output error message to console. To prevent such situation, Maven provides a concept of Remote Repository, which is the developer's own custom repository containing required libraries or other project jars.
For user-defined jars, you also need to specify :
<repositories>
<repository>
<id>in-project</id>
<name>Name_of_your_project</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
In standard configuration, Maven looks first in your local Maven repository (.m2/repository in your user directory) and if it does not find anything, it tries to download from the remote repositories that you specified. If you did not specify any, it will use MavenCentral.
When Maven finds something, it will be downloaded to the local Maven repository for future use. If you have -SNAPSHOT dependencies, they will be updated regularly.

Getting an error "Missing artifact com.beust:jcommander:jar:1.66" in maven pom.xml file.Any suggestion how to resolve this?

I have added the required dependencies in maven pom.xml file.
Downloaded the dependencies in pom.xml file via Maven Install option
Updated the project.
After updating the project, i found the error message "Missing artifact com.beust:jcommander:jar:1.66" in pom.xml file.
I have tried including the dependency of jcommander 1.66 version in pom.xml file but there is no change.
Any suggestions would be of great help. Thanks
Maven does not only need the dependencies in your POM, but also the transitive dependencies, i.e. their dependencies, the dependencies of their dependencies and so on.
This is why you let Maven connect to standard Maven repositories like MavenCentral. Except for unavailable artifacts, manual installation of artifacts should be avoided.

How to deploy maven parent pom.xml into artifactory?

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...

What does it mean to say that a pom is installed in local repository?

From the book Maven: The Complete Reference inside the section 3.6.1. Grouping Dependencies it says :
If you create this project in a directory named persistence-deps, all
you need to do is create this pom.xml and run mvn install. Since the
packaging type is pom, this POM is installed in your local repository.
You can now add this project as a dependency and all of its
dependencies will be added as transitive dependencies to your project.
When you declare a dependency on this persistence-deps project, don’t
forget to specify the dependency type as pom.
What does it mean to say that a pom is installed in local repository?
Every time Maven needs to find a a dependency, it first looks in the local repository - commonly located in an .m2 directory in your user home. If it can't find the dependency there, it downloads the dependency into your local repository and uses it from there.
When it says a pom is installed in the local repository, it means the POM file was copied into the correct place in the local repository. Other projects you build locally can then resolve that dependency and use it.

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