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.
Related
There are a fair amount of questions online involving how to use Maven / Aether to download dependencies for a given artifact.
I am however stumped as to downloading the parent poms.
I have similar code found online that does
CollectResult result = system.collectDependencies(session, request);
However the result is strictly the dependencies (compile, test, provided, runtime etc..) of the given artifact.
I am trying to setup an "offline" maven repository and as such need all relevant pom files as well. Certain plugins set a parent pom that I need to make sure is included as part of this transitive closure.
Additional Rationale
I am working on developing a solution to wrap Maven applications as a Nix derivation.
In order to attain hermetic/reproducible builds Nix disallows access to the internet; which means using Maven traditionally does not work.
I can instead pre-hydrate a maven repository given the known dependencies.
I am working on a project https://github.com/fzakaria/mvn2nix which turns a Maven (pom.xml) into a full list of all dependencies needed so that they can be downloaded.
I have a large maven project with several dependencies. There is also an assembly that contains all files I want to deploy - which is not necessarily identical to the dependencies.
My question: How can I generate a textfile that contains all URLs to JAR-files maven usually downloads the artifacts from? Ideally only from those files in the assembly, but of all dependencies would do as well.
[Update]
My project consists of a root project which has several artifacts from subprojects and external artifacts as dependencies. All dependencies are either stored in my private Artifactory repository or can at least accessed via it using Artifactory as a proxy.
When I roll out a new release, I want to be able that the root project writes all it dependencies in a file, suitable that a client can download those dependencies. The client has no idea about repository structures (I'd like to avoid that), so I need full URLs or at least full pathes within an repository root.
In my multi-module Maven project, suppose I have two modules, car and horse. They both depend on a JAR file, transport.jar, a file not available in any online Maven repositories. As such, I need to find a way to make these modules depend on a file found somewhere in the project folder structure.
From what I understand, the default Maven solution would be to manually register the JAR file in the local repository. While this would work on a development machine, it breaks on the build server, which clears its local repository before each build.
I've been searching online on how to do this on and off for a while and found some helpful things, but nothing that completely works.
For instance, a common answer is to add a dependency to the file using <scope>system</scope>. However, not only do others claim that it's extremely bad practice to do so, it also doesn't work on the build server. (On a side note, I would also like to point out that using absolute paths to the JAR is also out of the question due to, again, it being built on several different machines.)
A more useful method I found was to define a local repository in the POM file, pointing towards the path file:${project.basedir}/lib. (Such as in this article) Unfortunately, if I place the JAR and repository definition in the car POM, I cannot successfully add a dependency to the JAR in horse. I've tried both with and without an additional reference to car in horse, as well as defining a second repository in horse, pointing to file:${project.basedir}/../car/lib. This problem would also remain if I tried to make a third module, transport-lib, specifically for wrapping the JAR dependency.
I could most likely add the JAR file to both modules and define two separate module-local repositories, but I really don't want to unless I have to due to the need to keep the two (often updated) JARs in sync etc.
So, my question is as follows: Can someone give me a confirmed-to-work method to have two modules depend on the same JAR file inside the project, given the parameters and restrictions mentioned?
Best solution is to use a repository manager like Archiva, Artifactory or Nexus and install that artifact into the repository manager. Afterwards you can use this artifact directly in your pom files without any issue.
Don't use the scope system, cause it will cause other problem after a release for other etc.
Typically, a maven built jar artifact will have it's pom included under META-INF. I recently noticed that the Spring jars don't have this. So, that causes me to wonder about the purpose of that pom.
It seems like maven retrieves the pom directly from the repository when it's doing things that require knowledge of the artifacts meta-data, e.g. when determining dependencies.
So, what's the embedded one for?
The Maven docs suggest two reasons for the pom in this location.
1) Merely for reference, as a convenience. As the docs say, it makes the artifact "self describing"
2) You can get at this information from within your application using Java. This enables the arfiact to auto-report it's version within the application.
http://maven.apache.org/guides/getting-started/index.html
The pom you will find in the repository is not necessarily the one used to build the artifact. It is aimed at the users of the artifact and can be customized when building your artifact.
The one included inside the artifact IS the one used to produce the artifact.
There are options to not have it included in the artifact.
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.