如何在子模块pom中获得基于超级pom的文件? [英] how to get the super pom basedir in a child module pom?

查看:140
本文介绍了如何在子模块pom中获得基于超级pom的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的maven项目中定义一个本地存储库.

I want to define a local repository in my maven project.

我有一个超级pom和几个子模块.我的文件结构是:

I've got a super pom and several child modules. My file structure is :

/root
    /repository
    /child
        pom.xml
    pom.xml

在我的超级pom中,我定义了:

in my super pom I define :

<repository>
    <id>my-local-repo</id>
    <url>file://${basedir}/repository</url>
</repository>

问题在于,在我的子pom中,我的超级pom中定义的存储库引用了/root/child/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...

有没有一种方法可以始终定义相对于超级pom的路径?

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 ?

推荐答案

在这种情况下,起初您可以尝试${project.parent.basedir}.
似乎不起作用,简单(本机)的方法是使用完整路径(/root/...)或尝试相对路径(../)而不是使用$ {basedir}变量.

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.

但是对我来说,一个很好的解决方案是将该配置外部化为属性文件.
您可以使用 properties-maven-plugin ( http ://mojo.codehaus.org/properties-maven-plugin/plugin-info.html ).

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 ).

使用此插件,可以读取在属性文件中定义的属性,就像在pom.xml中定义的属性一样.

With this plugin, properties defined on the properties file can be read just like properties defined inside pom.xml.

从插件站点开始:

如果您有一个名为teams.properties的属性文件,其内容如下:

If you have a properties file called teams.properties with this content:

toronto=raptors
miami=heat

与在pom.xml中声明以下内容相同:

Would be the same as declaring the following in your pom.xml:

<properties> 
  <toronto>raptors</toronto>
  <miami>heat</miami>
</properties>

这篇关于如何在子模块pom中获得基于超级pom的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆