Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the classifier name from Maven's properties?

Tags:

maven

What's the easiest way to get the classifier name from Maven's properties and use it as a variable in the pom.xml?

For example:

<properties>
   <final_jar>${project.build.finalName}-${classifier}.jar</final_jar>
</properties>

There is no mention of a classifier property in the official documentation.

Looking at the source of maven-jar-plugin, it seems that it's getting it from a property called maven.jar.classifier but it doesn't seem to be available outside the plugin. Is there any way to access it ?

like image 225
Jerome Serrano Avatar asked Feb 20 '15 16:02

Jerome Serrano


People also ask

What is classifier in POM xml?

classifier: The classifier distinguishes artifacts that were built from the same POM but differ in content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

What is Properties tag in Maven?

Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java.

What is name in Maven?

The name is used for the project used by maven to build the artifact, while the artifact-id is used to identify the artifact that will be built.

What is ${ project build finalName?

finalName: This is the name of the bundled project when it is finally built (sans the file extension, for example: my-project-1.0. jar). It defaults to ${artifactId}-${version}.


1 Answers

Despite of classifier being mentioned under POM Reference, Maven Coordinates it has to be declared in a maven-jar-plugin section. So (you name it) it's not part of the <project> element's Model.

Unfortunately, I too haven't found a way yet to access the maven.jar.classifier property of the maven-jar-plugin but by declaring an extra <project> property:

<project>
  ...
  <properties>
    <jar.classifier>CLASSIFIER</jar.classifier>
  </properties>
  ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <classifier>${jar.classifier}</classifier>
        </configuration>
      </plugin>
  ...
</project>

There's a Properties properties in the Maven Model's superclass ModelBase. But if it's not used by a plugin...

And there's also no property interpolation syntax (yet?) like:

${project.build.plugins.plugin[<G>:<A>:<V>].<property>}
like image 93
Gerold Broser Avatar answered Oct 21 '22 08:10

Gerold Broser