如何在子模块pom中获取超级pom basedir?
我想在我的 Maven 项目中定义一个本地存储库。
我有一个超级 pom 和几个子模块。我的文件结构是:
/root
/repository
/child
pom.xml
pom.xml
在我的超级pom中我定义:
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/repository</url>
</repository>
问题是在我的子pom中,我的超级pom中定义的存储库引用/root/child/repository,因此,无法找到依赖项...
有没有办法定义始终相对于超级 pom 的路径?
如果不是,解决问题的最佳方法是什么?
I want to define a local repository in my maven project.
I've got a super pom and several child modules. My file structure is :
/root
/repository
/child
pom.xml
pom.xml
in my super pom I define :
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/repository</url>
</repository>
The problem is that in my child pom, the repository defined in my super pom refers to /root/child/repository and so, dependencies cannot be found...
Is there a way to define a path always relative to the super pom ?
If not, what's the best way to solve the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在这种情况下,首先您可以尝试
${project.parent.basedir}
。因为它似乎不起作用,简单(和本机)的方法是使用完整路径(/root/...)或尝试相对路径(../)而不是使用 ${basedir} 变量。
但对我来说,一个很好的解决方案是将这个配置外部化到属性文件中。
您可以使用 properties-maven-plugin ( http ://mojo.codehaus.org/properties-maven-plugin/plugin-info.html)。
使用此插件,可以像 pom.xml 中定义的属性一样读取属性文件中定义的属性。
从插件站点:
如果您有一个名为 team.properties 的属性文件,其中包含以下内容:
与在 pom.xml 中声明以下内容相同:
In this case, at first you could try
${project.parent.basedir}
.As it seems it doesn't work, the simple(and native) way is use complete path (/root/...) or try relative path (../) instead of using ${basedir} variable.
But for me, a great solution would be externalize this configuration into a properties file.
You can use properties-maven-plugin ( http://mojo.codehaus.org/properties-maven-plugin/plugin-info.html ).
With this plugin, properties defined on the properties file can be read just like properties defined inside pom.xml.
From the plugin site:
If you have a properties file called teams.properties with this content:
Would be the same as declaring the following in your pom.xml:
${project.parent.basedir}
应该可以完成这项工作。或者您可以在属性中设置根的 basedir-path,这样它将被继承。父母
和孩子身上都有类似的事情
${project.parent.basedir}
should do the job.Or you can set the basedir-path of the root in a property, so it will be inherited. Something like this in the Parent
And in the Child
我用 groovy 插件多次解决了这个问题。将一个名为“basepath_marker”的文件添加到您的超级 pom 目录中,并将以下内容添加到您的 pom.xml 中:您可以像这样访问该属性:${base-path}。阅读 此内容博客文章了解更多详细信息。
例子:
I solved this many times with groovy plugin. Add a file called "basepath_marker" to your super pom's directory and add the following to your pom. You can access the property like this: ${base-path}. Read this blog post for more details.
Example:
我在子 pom 中尝试
${basedir}/../
并且它有效。${project.parent.basedir}
无法解释。另外,以下解决方案不起作用,似乎
${basedir}
是动态决定的。${basedir}
int 你的父 pom${rootPath}
I try
${basedir}/../
in child pom and it works.${project.parent.basedir}
can not be interpreted.Also the solution as follow not work, seems
${basedir}
is dynamic decided.<rootPath> ${basedir} </rootPath>
int your parent pom${rootPath}
in your child pom在父 pom 中 -
尝试使用相对路径 (
../
) 而不是使用${basedir}
In Parent pom -
Try to use relative path (
../
) instead of using${basedir}