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}
?
That being said, if the version is not given, then the version provided in the dependencyManagement or the parent pom will be used. For example: in the pom (only important sections are mentioned) given below, no version is provided for the artifact jstl.
There are two types of dependencies in Maven: direct and transitive. Direct dependencies are the ones that we explicitly include in the project.
What Is Maven Dependency Management? Dependency management in Maven allows teams to manage dependencies for multi-module projects and applications. These can consist of hundreds or even thousands of modules. Using Maven can help teams define, create, and maintain reproducible builds.
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. Now this property( java.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With