What is the purpose of a Mavens dependency dependency classifier property?

I have a pom.xml file and I see that they have 3 dependencies referenced by the same <artifactId> , the difference in tags

 <classifier>sources</classifier> <classifier>javadoc</classifier> 

I removed the dependencies that had SOURCES/JAVADOC and kept only one dependency. I tested my application and everything works great.

What is the purpose of using this classifier tag? and why do I need to duplicate the dependencies twice to add the <classifier> tag using SOURCES/JAVADOC .

 <dependency> <groupId>oauth.signpost</groupId> <artifactId>signpost-commonshttp4</artifactId> <version>1.2.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>oauth.signpost</groupId> <artifactId>signpost-commonshttp4</artifactId> <version>1.2.1.2</version> <type>jar</type> ***<classifier>javadoc</classifier>*** <scope>compile</scope> </dependency> <dependency> <groupId>oauth.signpost</groupId> <artifactId>signpost-commonshttp4</artifactId> <version>1.2.1.2</version> <type>jar</type> ***<classifier>sources</classifier>*** <scope>compile</scope> </dependency> 
+59
java maven dependency-management
Jan 03 '14 at 17:45
source share
5 answers

The classifier distinguishes artifacts that were created from the same POM, but differ in content. This is some optional and arbitrary string that - if present - is added to the artifact name immediately after the version number.

Source

+47
Jan 03 '14 at 17:48
source share

Classifier example
As a motivation for this element, consider, for example, a project offering an artifact aimed at JRE 1.8, but at the same time also an artifact that still supports JRE 1.7. The first artifact can be equipped with the jdk18 classifier, and the second with jdk14, so customers can choose which one to use.

Another common use of classifiers is the need to connect secondary artifacts to the main artifact of the project. If you look at the central Maven repository, you will notice that classifier and javadoc sources are used to deploy project source code and API documents along with packed class files.

+5
Aug 05 '15 at 9:01
source share

Another more pragmatic example answer is to better understand the usefulness of classifier .

Suppose you need two versions of an artifact: for openjpa and for eclipselink - let's say because the jar contains objects that are needed for a particular JPA implementation.

You may have some different processing for these assemblies defined in Maven profiles, and the profiles used also have the <classifier /> property.

To build different classified versions, the pom maven-jar-plugin will then be configured as follows

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <classifier>${classifier}</classifier> </configuration> </plugin> 

Installing both will cause the files in the repo to look something like this:

org / example / data / 1.0.0 / data 1.0.0.pom
org / example / data / 1.0.0 / data 1.0.0-openjpa.jar
org / example / data / 1.0.0 / data-1.0.0-eclipselink.jar

Now there will only be a classifier question to be used, therefore

 <dependency> <groupId>org.example</groupId> <artifactId>data</artifactId> <version>1.0.0</version> <classifier>[openjpa|eclipselink]</classifier> </dependency> 
+2
Dec 09 '17 at 21:32
source share

It allows you to distinguish between two artifacts belonging to the same POM, but created in different ways and added to the file name after the version.

For example, if you have other artifacts in your repository (documents, sources ...), you can link to them and add them to your project as a dependency. in this code, adding <classifier>sources</classifier> , we get source.jar from the repository.

  <dependency> <groupId>oauth.signpost</groupId> <artifactId>signpost-commonshttp4</artifactId> <version>1.2.1.2</version> <type>jar</type> ***<classifier>sources</classifier>*** <scope>compile</scope> </dependency> 

In fact, this allows you to find your dependencies with a further level of detail.

+1
Jan 13 '17 at 9:29 on
source share

According to the following: https://blog.packagecloud.io/eng/2017/03/09/how-does-a-maven-repository-work/ in the classifier tag means "Secondary artifact", which will be disabled by "transitive dependency "! Thus, the classifier tag not only changes "Maven Coordinate" to $ artifactId- $ version- $ classifier.jar!

0
Nov 01. '17 at 17:04 on
source share



All Articles