find out from which maven repository the jar is coming from - maven

There is a plugin that works properly in my co-worker's system but doesn't in mine. I suspect it because of a repository included in his settings.xml but not in mine. Is there a tool that I can use to figure out from which repo is this plugin being downloaded from?

Maven stores that info in a file called _maven.repositories in your local maven repository (typically ~/.m2/repositories) for each artifact. The file is located right beside the corresponding artifacts in the local maven repository.
This file will typically list the repository / plugin-repository that the artifact was downloaded from. This matches to the repository from your settings.xml file.

In Maven 3, the file seems being changed to _remote.repositories

Related

Maven Repository URL

I am new to maven and trying to understand how it works.
I am using maven to build my project. It download the jars that I have listed in pom.xml file. I do Maven Intall (eclipse), it downloads the jar file in my .m2/repository folder. Everything works well but I cannot figure out how it knows to pull the jar files from https://repo.maven.apache.org/maven2/. In which file, this url is defined. I do not have setting.xml file in .m2/repository and I do not have reference to https://repo.maven.apache.org/maven2/ in pom.xml. I searched everywhere in my project but no references to this URL. Just wondering which file has this URL.
thank you so much
The Maven Central Repository is defined in the Maven "Super POM".

Download Maven artifacts in Jenkins from another repo if one fails

In my Jenkins build I have a settings.xml file for pulling Maven dependencies. An artifact, if not found, should be downloaded from another Maven repo not specified in a settings file. Can this be done using code in Jenkinsfile? Any thought will be greatly appreciated.

Must you create the .m2/repository folder manually

Will the .m2 folder be created automatically by Maven, or do you need to create it manually?
What does the .m2/repository, contain and from where does it come?
First, it will be created by Maven when you execute a build, such as:
mvn clean install
Note, you could find this out just be executing mvn your self ;)
Second, the contents of .m2 are:
A settings.xml file that contains global settings for all maven executions.
A folder called repository that holds all of the local copies of various maven artifacts, either caches of artifacts pulled down from remote repositories, such as Maven Central, or artifacts built by your local maven builds. The artifacts are organized in there in folder structures that mirror the groupId's of the artifacts.
It will be created automatically. The repository folder (also called local repository) will download its content from repositories specified in your user's settings.xml, the global settings.xml and possibly in your poms.
Most artifacts will be downloaded from repo1.maven.org.

What is meant by local repository and remote repository in Maven?

I am reading up Maven - The complete reference and came across this
Maven assumes that the parent POM is available from the local repository, or available in the parent directory (../pom.xml) of the current project. If neither location is valid this default behavior may be overridden via the relativePath element.
What exactly is meant by local and remote repository for a Maven installation and a project?
A local repository is a local directory structure that caches artifacts downloaded from remote repositories, or those that are manually installed (eg from the command line option).
A remote repository is a web service (defined by a URL) that contains versioned artifacts. This might be as simple as an Apache server, or a full-blown Maven repository, such as Artifactory, that allows uploading, permissions based on a user directory, etc.
http://maven.apache.org/guides/introduction/introduction-to-repositories.html
By default, Maven will source dependencies from, and install dependencies to, your local .m2 repository. This is a precedence rule, and your .m2 acts like a cache where Maven can source dependencies before downloading them remotely. You can bypass this behaviour like so: mvn -U ... (see mvn --help).
Your local .m2 can be found under C:\Users\{user}\.m2 on Windows, or /home/{user}/.m2 on Linux. If you do a mvn install, your project will be locally installed under the said .m2 repository.
A remote repository is a Maven repository, just like your local .m2 repository, hosted for you to source dependencies from, e.g. Maven Central.
Local repository is a repo. Into your local system, when you compile or install project all required dependencies downloaded into your local repo.
When you're working with your project, then Maven first tries to get dependencies from local. If it's not available, then Maven will try to download the dependency from a central repository.
central repo. is a online repo, which is provided by maven itself.

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