Reputation: 10300
I have spring boot project and I try to use spring boot dependency-management plugin to be able to use provided dependency versions.
The plugin 'simulates' mavens BOM behaviour, which means that it somehow retrieves versions of libs from maven parent project (I'm not sure how exatly this gets acheived, but generally versions are taken from pom.xml). It does have jackson.version
property that is used to setup versions for artifacts within com.fasterxml.jackson.dataformat
group.
My project uses artifact from the same group, however it is not included into the BOM (jackson-dataformat-yaml
) but I want to use the same jackson version.
I tried adding compile dependency like this:
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jackson.version}"
but build fails with:
Could not get unknown property 'jackson' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Q: Is there a way to access the property? Or how else can I reuse the lib version?
UPDATE I'm not sure why didn't I try this from the very beginning, but it works:
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"
However I have no clue why this works (the artifact is not declared anywhere).
Upvotes: 7
Views: 1655
Reputation: 29150
However I have no clue why this works (the artifact is not declared anywhere).
So it is a concern that you are not using any version, but how it works?
Actually gradle use some rules. Those are given below:
Gradle will use transitive dependency management for specifying actual version.
On the other hand it will use first level or second level hierarchy of repositories to take the latest version.
From spring documentation,
Maven’s dependency management includes the concept of a bill-of-materials (bom). A bom is a special kind of pom that is used to control the versions of a project’s dependencies and provides a central place to define and update those versions.
For more you can go through this tutorial: Gradle dependencies with jars that have no version number
plugins { id 'org.springframework.boot' version '1.5.8.RELEASE' id 'java' } repositories { jcenter() } dependencies { compile("org.springframework.boot:spring-boot-starter-web") testCompile("org.springframework.boot:spring-boot-starter-test") }
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html
How are some gradle dependencies working with no version supplied
Upvotes: 1
Reputation: 5105
After question is updated with working example, I'll try to answer why it works without specifying the version instead:
The pom.xml you are referring to contains the dependency
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
... which refers to the following pom.xml in the jackson-bom project, which in turn contains the following dependency:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version.dataformat}</version>
</dependency>
... which in turn specifies the version of the jackson-dataformat-yaml artifact...
Upvotes: 1
Reputation: 84786
It happens because when .
(e.g. ${a.b}
) is used in string interpolation in groovy it treats being the precedes .
as an object which has a property that follows .
. So in ${a.b}
object a
should have property b
or it will fail. In you example jackson
is an instance of String
and it has no version property. To solve it you can use e.g. jacksonVersion
or a Map
. See a demo here.
Upvotes: 0