Copy two versions of same jar using maven - maven

I am writing pom.xml for our project. I need to copy two different versions of same jar. But I searched maven docs and found that Maven has no support for this. Is there any other way to do that?
Note: Both jars have same groupid and artifact id.Only their versions are different.
Thanks in advance!

As you already know, Maven was designed to make sure that you will never have two JARs with the same coordinate (group + artifact id) but different versions on the classpath.
There is no way to achieve what you want without modifying the POMs of the JARs
So you need a workaround. Here are a couple of solutions:
Give the JARs different classifiers. Typical classifiers are "tests" and "sources" but they can be anything.
Move the version number to the artifact id and give the two JARs a new version.
For all approaches, you will need to download the JARs (and probably their POMs as well) and install them again using mvn file:install (after changing the POMs) or deploy them with mvn deploy:file if you run your own Maven proxy.

Related

Identify maven dependency from list of jars

I am trying to convert my existing web app project into maven. I have a bunch of jars in my project manually downloaded and kept in a directory. While converting to maven, I need the name of group id and artifact id of these jars so that I can mention it in pom.xml.
Is there any other way than manually searching for each jar name in mvnrepository.com?
I think you're slightly out of luck. There might be a chance that some of the jars contain the information you're looking for under
META-INF/maven/<groupId>/<artifactId>/pom.properties
But other than that, #JFabianMeier is right, it's manual labor. And please be aware that Maven uses transitive dependencies that may affect your classpath differently than when you specify the jars from a directory.
You might have to add exclusions to your POM's transitive dependencies to get the classpath as you want it.

Gradle finds POM for dependency but not JAR

We are hosting a local maven repository in Sonatype Nexus, in order to share our own jars across projects. We are having an issue with one jar in particular, where Gradle is able to find and download the POM, but not the JAR from Nexus.
The error given in Gradle is simply:
Could not resolve: com.qf:qf-etl_2.11:0.0.1-SNAPSHOT
We have not this problem with any other jar held in Nexus. There is one possibly notable difference between this jar, and other jars we are hosting, which is that this jar depends on another jar which is also held in our locally hosted maven repository.
We are using Gradle 2.14, and Nexus 3.0.1-01 (ESS)
All help and ideas are appreciated, and please let me know what additional information I need to provide!
The POM was downloading without the JAR, because the JAR depended on two unmanaged (3rd party) JARs. The solution that I followed was to upload the third party JARs into Nexus as well, so that these could be found, guided by these instructions
Note that gradle:eclipse was not reporting missing dependencies, even though it would normally do this.

What is the purpose of the pom.xml inside a jar's META-INF folder?

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.

different dependencies for different classifiers in maven

I have a Maven artifact with a couple of dependencies. I want to publish the module built into a jar as normal, but I also want to publish a jar with its dependencies inside it using the maven shade plugin. This uber jar has a different classifier.
This all works fine, except if someone pulls in the uber jar using its classifier, they still get all the dependencies of the original, which they don't need.
How can I exclude certain dependencies based on the classifier? I have tried using profiles but I can't work out how to activate a profile based on the classifier of the artifact.
I know I could have the uber jar as a whole new artifact doing the exclusion itself, but that's a bit messy, I was hoping there was a better solution?
Try optional dependency. You have to declare all of your dependencies in the uber jar artifact's optional value to true.
Also, instead of using classifier, you might want to create another artifact. You can adapt this from mockito. See mockito-core vs mockito-all.

Maven and ibiblio

I searched a lot in apache documentation and ibiblio.org and I could not find a decent straight answer.
My questions:
When I download a jar using maven dependency (setup in pom), how can I be sure that the file does not change on the remote repository? for example, if I'm using log4j version 1.2.3, downloaded from ibiblio.org (or any other repo for that matter), how can I be sure I'm getting the exact same jar each time?
Does maven delete jars from the local repository? let's assume I'm not clearing the repository at all, will it fill up eventually? or does maven have some kind of mechanism to clear old jars?
In Maven conventions a released version like log4j 1.2.3 will never be changed. It will be left in your locale repository until you manually delete it. It can't be changed by anyone except for the admins on maven central, but i suppose they don't do such a stupid thing.
Furthermore the download by default is done from maven central (repo1.maven.org/maven2 instead of ibiblio).
One of the "tricks" in Maven is download an artifact (released) only once...that improved your build performance in contradiction to the SNAPSHOT dependencies.
You could configure your own repository, and point all your project poms at that. It's easy to configure your poms to use a different (private) repository, but I've never set one up myself. Doesn't seem too hard, other than managing it to keep all the needed artifacts available.

Resources