Find Maven repository where a dependency is stored - maven

I'm working on a project with several corporate remote Maven repositories, each hosting many dozens of dependencies. The entire project uses hundreds of dependencies and I need a way to quickly determine which remote repository a dependency is stored on.
Does Maven provide an easy way to do this or do I need to search through each repository's dependency listing myself?

The project dependencies report has the information you want. You can quickly generate just this report using
mvn project-info-reports:dependencies
and open the target/site/dependencies.html file. Look at the last section in this report (dependency repository locations) for the info you want.
A sample of this report is here.

Related

Confused with maven assembly plugin vs build-helper-maven:attach-artifact

I'm a bit confused between maven assembly plugin and build-helper-maven plugin.
I've also read in the maven documentation that The assemblies/archive created by the Assembly Plugin gets deployed during the deployed phase.Hence, they can be deployed to the remote nexus repositories.
The purpose of maven assembly plugin is to archive many things into one(say in tar.gz format).
However, the attach-artifact goal present within build-helper-maven plugin has the same role i.e.archiving,installing and deploying the artifact.
With that being said,why would anyone use both of them together? I've seen people using both of them together. Isn't one of the plugins an alternative choice of the other?
Kindly advise.
If you use maven-assembly-plugin you can create as you already mentioned any kind of archives (range from very simple to very complex structures) they will be by default be attached to your project which means they will be deployed into remote repositories in one go if you do mvn deploy with no supplemental configuration.
The build-helper-maven-plugin is intended to add an artifact (one goal of this plugin) which is usually not generated by Maven itself which most of the cases is a smell. If people using them together (in the use case to create an archive and attach it) this makes no sense.
Apart from that the build-helper-maven-plugin can also be used to add other source directories for example for scala, kotlin projects (other goals for example add-source etc.)
So those plugins are not alternatives they have different intentions/use cases.

Obtaining all parent poms in a repository

I have a huge local repository, which also contains unneeded jars (they are needed for other projects, but not for the task at hand). I've extracted the dependencies of my project using the maven dependency plugin and parsed that information into deploy commands in order to deploy those jars to another, remote repository. I couldn't have copied directly, because of access restrictions.
However, now compilation fails and I discovered that many of the issues I've already solved were due to the fact that the parent poms for some of the jars I was using were missing.
Is there a way to programmatically obtain all the parent poms of the dependencies of a certain project, similar to finding the dependencies themselves?
I would try parsing the directory tree directly and deploying every pom which doesn't have a jar counterpart, but I really hope there are better alternatives.

How to depend on a local library with maven

I have a project contains two sub projects:
A. a common library for external api
B. a program depends on above library
They are inside same directory. How I made B refer to A with maven?
Normally you will always share through a maven repository. That is mavens way to ensure a consistent and correct solution and a solution shareable by all developers.
You should search for a public maven repository with project A (e.g. http://search.maven.org or http://mvnrepository.com) and include in your pom
If it does not exist in public (is proprietary in someway or other), consider using an enterprise-wide maven repository such as nexus or artifactory to push to repositories.
Finally, some developers resort to either installing a mvn-local file if you are ever only going to work on an explicit workstation.
If you still prefer a filebased acces, it is possible to define a maven file repository and reference it in your pom. E.g. Heroku use this for bundling extra dependencies into their system.
Declare A as dependency in B's pom.xml. Make sure A has valid pom.xml and is deployed to your repository (local/nexus). We do that all the time. Take care to assign SNAPSHOT version if you always want latest to be pulled from repository.

broken classpath with Intellij Idea on maven dependency

i'm using Intellij IDEA 12.1.6, almost everyone in my company use Eclipse and dont notice my problem. We have a local nexus repository where we deploy artifacts, but some of them are systematically created with an invalid maven-metadata.xml (the latest snapshot timestamp and build number does not match the effective artifact name on repo) and intellij ends up telling me those libraries have broken classpath.
Is there a way to force intellij on hooking the maven jars on my local repository without worrying about those metadata additional information? Eg eclipse hook the jar in his classpath taking the version which does not include those data (in my m2 repo dir i see both 2 jars downloaded, the one with full data and the other one without them)
eg.
library-0.0.6-SNAPSHOT.jar
library-0.0.6-SNAPSHOT-20131028.111135-10.jar
Thank you for your help.
If Importing the eclipse project did not work. You should be able to Configure the library contents . The step for Configure Library Dialog should allow you to point the library to a different location.

How to make my maven project depend on non maven projects?

I want to create a maven project, which has to depend on a non maven project which in turn depends on 2 other non maven projects. I do not have ownership of any of the other projects and it would not be possible for me to change anything in those projects let alone the structure to conform to the maven structure.
I asked if I could just get jars -- but was told that because of multiple levels of dependency, it would be "difficult" -- although I haven't understood why.
Is this possible or should I just abandon the use of maven to create my project and go with a regular project with jars in the lib folder?
Inxsible
If you can go with a regular project build that means you must have access to the other project's jar files?
It doesn't really matter how the other project builds them, you can still gain more control over your own build process by loading the jars you depend on into a Maven repository.
I'd suggest using one of the following repository managers:
Nexus
Artifactory
Archiva
They'll give you management screens to uploading 3rd party jars, they'll also a more efficient way to use other Maven repositories like Maven Central.
Once you've got your Maven build process working, you could encourage the other projects to automatically publish their versions into your Maven repo.
They could use the ANT tasks provided by the Maven or Apache ivy projects. Worst case you just continue to load their libraries until they see the light :-)

Resources