Ring
Ring

Reputation: 2309

Maven Dependency Version As Property

I have a maven pom file that defines a dependency as such:

<dependencies>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.3.6</version>
    </dependency>
</dependencies>

It is often said that everything in the pom can be referenced as a Maven property:

https://bowerstudios.com/node/991

For example, you can read ${project.version}, ${project.build}, etc. Is there a way to read a dependency's version as a Maven property, ala ${project.dependencies.dependency.groupId=org.apache.httpcomponents&artifactId=httpclient.version} ?

Upvotes: 13

Views: 17537

Answers (1)

Balaji Katika
Balaji Katika

Reputation: 3005

You could define a custom property under <properties> and refer to it from your dependency. Preferred way is to place the property in parent pom (if exist and is a multi module project). Alternately, you can skip the <version> altogether if you had defined the <dependency> in <dependency-management> section

<properties>
<http.client.version>4.3.6</http.client.version>
</properties>
...
<dependencies>
   <dependency>
     <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpclient</artifactId>
     <version>${http.client.version}</version>
   </dependency>
</dependencies>

Upvotes: 25

Related Questions