问题
I am building a spring boot starter, following the recommended convention with core / autoconfigure / starter module separation. When I look at the maven dependency-tree, this is what I have :
[INFO] com.myDomain.myProject:myProject-starter:jar:1.0.8-SNAPSHOT
[INFO] +- com.myDomain.myProject:myProject-autoconfigure:jar:1.0.8-SNAPSHOT:compile
[INFO] | \- com.myDomain.myProject:myProject-core:jar:1.0.8-SNAPSHOT:compile
[INFO] | +- io.github.openfeign:feign-gson:jar:9.5.1:compile
[INFO] | | +- io.github.openfeign:feign-core:jar:9.5.1:compile
[INFO] | | \- com.google.code.gson:gson:jar:2.8.5:compile
gson comes in v2.8.5, which is the version I expect - my project works with it
(note : in https://mvnrepository.com/artifact/io.github.openfeign/feign-core/9.5.1 , we see that the expected version for gson is 2.5... so not sure why I get 2.8.5..)
In my root pom.xml, I declare the BOM like this :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-dependencies</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and in my "core" pom.xml :
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-gson</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
</dependencies>
Now, in another project, I use the starter. So my pom.xml is very simple :
<dependencies>
<dependency>
<groupId>com.myDomain.myProject</groupId>
<artifactId>myProject-starter</artifactId>
<version>1.0.8-SNAPSHOT</version>
</dependency>
</dependencies>
When I look at the dependency tree in this project, I get this :
[INFO] \- com.myDomain.myProject:myProject-starter:jar:1.0.8-SNAPSHOT:compile
[INFO] +- com.myDomain.myProject:myProject-autoconfigure:jar:1.0.8-SNAPSHOT:compile
[INFO] | \- com.myDomain.myProject:myProject-core:jar:1.0.8-SNAPSHOT:compile
[INFO] | +- io.github.openfeign:feign-gson:jar:9.5.1:compile
[INFO] | | +- io.github.openfeign:feign-core:jar:9.5.1:compile
[INFO] | | \- com.google.code.gson:gson:jar:2.5:compile
gson comes in v2.5, and because of that it doesn't work. If I override it in the pom.xml, by declaring gson 2.8.5 before the starter, then it works..
But there must be something that I am missing in the way Maven works..
I've tried deleting the 1.0.8-snapshot version from my local repo, then rebuild, it, to make sure my second project was not taking an older version, but I keep getting this incorrect version in my build, and I have no clue where it's coming from / what overrides it.
code is available in this branch if you want to give it a try locally : https://github.com/societe-generale/github-crawler/tree/sprinBoot2upgrade
I am really interested in any pointer for investigation, to understand the root cause, because I am quite confused right now..
Thanks !
=========================================
EDIT 1
As mentioned in comments, it's Spring Boot starter that overrides the gson version to 2.8.5 (instead of the 2.5 planned in feign-core).
So now the question becomes : how come that when I use the starter as the single dependency in another project with no parent, that overridden version (2.8.5) disappears and I end up with the initial version (2.5) that is not compatible with spring-boot-autoconfigure 2.0.4.RELEASE ?
EDIT 2
I have created a fresh, more focused question here : Not getting the expected version when using the Spring Boot starter I built
回答1:
quick summary based on the various hints in the question comments
Verbose mode is discontinued since Maven 3.x, so use mvn dependency:tree -X to get more details on versions used/overridden, etc. Then you get something like that :
[DEBUG] io.github.openfeign:feign-gson:jar:9.5.1:compile
[DEBUG] com.google.code.gson:gson:jar:2.8.5:compile (version managed from 2.5 by org.springframework.boot:spring-boot-dependencies:2.0.4.RELEASE)
-> this points quite clearly to where the version is coming from, ie https://github.com/spring-projects/spring-boot/blob/v2.0.4.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml#L65
来源:https://stackoverflow.com/questions/52138170/where-does-the-maven-version-get-overridden