在 Maven 中查找定义了属性的位置 [英] Find in maven where a property is defined
问题描述
我目前正在重构各种项目和 git repo 中的大量 pom.xml.有时,项目 A 中的 pom 将需要在项目 B 中以属性定义的版本定义的工件:
<依赖><groupId>com.example</groupId><artifactId>artifact-from-b</artifactId><version>${version.from.somewhere}</version></依赖>
有时,在 pom 本身或其父 pom 中没有明显定义 version 属性.它可以隐藏在父级父级的父级...
我目前正在尝试找到一种方法来轻松解析 ${version.from.somewhere} 等属性并找到它的定义位置.
任何可以帮助我的工具的想法(除了 eclipse,它因某些棘手的属性而失败)?
谢谢!
这里有一个相关的答案 有没有办法在 maven pom 中追踪属性的来源?
建议使用 mvn help:effective-pom -Dverbose=true
然后你可以找到类似 com.example.model:2.1.0-SNAPSHOT
的评论.>
我试过了,它对我有用.
在我的例子中,该属性定义在 com.example.model:2.1.0-SNAPSHOT
的 pom 中的第 407 行
<依赖><groupId>com.example</groupId><!-- com.example.model:2.1.0-SNAPSHOT, line 405 --><artifactId>模型</artifactId><!-- com.example.model:2.1.0-SNAPSHOT, line 406 --><version>1.0.6</version><!-- com.example.model:2.1.0-SNAPSHOT, line 407 -->
I'm currently refactoring lots of pom.xml in various projects and git repo. Sometimes, a pom in a project A will require an artifact defined in a project B in a version defined by a property :
<dependency>
<groupId>com.example</groupId>
<artifactId>artifact-from-b</artifactId>
<version>${version.from.somewhere}</version>
</dependency>
Sometimes, the version property is not obviously defined in the pom itself or its parent pom. It can be hidden in a parent's parent's parent...
I'm currently trying to find a way to resolve easily properties like ${version.from.somewhere} and find where it is defined.
Any idea of any tool that can help me (apart from eclipse, which fails for some tricky properties) ?
Thanks !
There is a related answer here Is there a way to trace origin of a property in maven pom?
That suggest using mvn help:effective-pom -Dverbose=true
then you can find comments like com.example.model:2.1.0-SNAPSHOT
.
I tried it and it worked for me.
In my case, the property is defined in the pom of com.example.model:2.1.0-SNAPSHOT
in line 407
<dependency>
<groupId>com.example</groupId> <!-- com.example.model:2.1.0-SNAPSHOT, line 405 -->
<artifactId>model</artifactId> <!-- com.example.model:2.1.0-SNAPSHOT, line 406 -->
<version>1.0.6</version> <!-- com.example.model:2.1.0-SNAPSHOT, line 407 -->
这篇关于在 Maven 中查找定义了属性的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!