You work with a complex maven project. That’s a fact, otherwise you wouldn’t be here, searching to uncover a way out of its dependencies maze.
Your project probably has a parent
, as your parent
might also have one.
You may have boms
in your dependency management, but your parent
certainly has one too.
You defined properties
, and guess what, so have at least a dozen direct or transitive dependencies.
So after having done your research, not relying on some gibberish from whatever AI assistant you usually use, you found out about :
mvn dependency:treemvn dependency:treemvn dependency:tree
Enter fullscreen mode Exit fullscreen mode
While that does give you a nice console output, chances are it’s not enough. Again, you wouldn’t be here if it was.
It does tell you the dependency version used, where they were pulled out from, but why is that specific version used can still be unclear.
Let’s say you have a dependency somewhere in you project hierarchy defined as followed:
<span><dependency></span><span><groupId></span>org.springframework.boot<span></groupId></span><span><artifactId></span>spring-boot-starter-web<span></artifactId></span><span><version></span>${spring.boot.version}<span></version></span><span></dependency></span><span><dependency></span> <span><groupId></span>org.springframework.boot<span></groupId></span> <span><artifactId></span>spring-boot-starter-web<span></artifactId></span> <span><version></span>${spring.boot.version}<span></version></span> <span></dependency></span><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring.boot.version}</version> </dependency>
Enter fullscreen mode Exit fullscreen mode
The property value is defined to be 3.4.4
in your parent, but the the dependency:tree
plugin output tells you the value is 2.7.9
, and so you rightfully ask yourself, why the f… is that.
Well it just happens that this can be easily solved using the help
plugin:
mvn <span>help</span>:effective-pom <span>-Dverbose</span><span>=</span><span>true</span>mvn <span>help</span>:effective-pom <span>-Dverbose</span><span>=</span><span>true</span>mvn help:effective-pom -Dverbose=true
Enter fullscreen mode Exit fullscreen mode
It will spit out your pom as seen by the great maven
itself. The only issue is that chances are great that your console buffer will be overflowed. But we are smarter than that.
mvn <span>help</span>:effective-pom <span>-Dverbose</span><span>=</span><span>true</span> | <span>grep </span>spring.boot.versionmvn <span>help</span>:effective-pom <span>-Dverbose</span><span>=</span><span>true</span> | <span>grep </span>spring.boot.versionmvn help:effective-pom -Dverbose=true | grep spring.boot.version
Enter fullscreen mode Exit fullscreen mode
It will give you something like :
<spring.boot.version>2.7.9</spring.boot.version> <span>\</span><<span>!</span><span>--</span> com.acme:your.exotic.dependency:17.0.18-RC3-FINAL-GA, line 253 <span>--</span><span>></span><spring.boot.version>2.7.9</spring.boot.version> <span>\</span> <<span>!</span><span>--</span> com.acme:your.exotic.dependency:17.0.18-RC3-FINAL-GA, line 253 <span>--</span><span>></span><spring.boot.version>2.7.9</spring.boot.version> \ <!-- com.acme:your.exotic.dependency:17.0.18-RC3-FINAL-GA, line 253 -->
Enter fullscreen mode Exit fullscreen mode
There! You have it! Of course your exotic dependency is the culprit. Now that you know it, it will be much easier to fix. Don’t you think ?
原文链接:So you wanna know where your maven dependency version comes from ?
暂无评论内容