Maven $ {basedir}在多模块设置中的用法 [英] Usage of maven ${basedir} in multi-module setup

查看:3194
本文介绍了Maven $ {basedir}在多模块设置中的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本地存储库,如中所述Maven:通过相对路径向jar添加依赖项..

I am using a local repository as described in Maven: add a dependency to a jar by relative path.

存储库URL在最顶部的pom.xml中定义为

The repository-url is defined in the topmost pom.xml as

<url>file:${basedir}/../3rdParty/maven-repository</url>

此外,最上面的pom.xml定义了2个模块

Also, the topmost pom.xml defines 2 modules

<modules>
    <module>sub1</module>
    <module>sub2</module>
</modules>

问题是,如果模块(例如sub1)定义了应从存储库下载的依赖项,并且从最顶层的目录调用了maven,则${basedir}不会设置为该目录,而是设置为sub1,导致存储库URL错误.

The problem is, that if a module (say sub1) defines a dependency that should be downloaded from the repository, and maven is called from the topmost directory, the ${basedir} is not set to this directory, but to sub1, resulting in a wrong repository-URL.

因此,假设具有最高pom.xml的项目位于

So, say the project with the topmost pom.xml resides in

/Development/myproject/pom.xml

存储库位于

/Development/3rdParty/maven-repository

然后将存储库URL设置为

Then the repository URL should be set to

/Development/myproject/../3rdParty/maven-repository

但事实证明它设置为

/Development/myproject/sub1/../3rdParty/maven-repository

那当然不存在.

知道为什么会这样吗?

推荐答案

尽管您的情况很烦人,但这是众所周知的和故意的.无论在什么上下文中执行,maven项目都应该只知道其执行目录.

Although it is annoying in your case, this is well-known and intentional. A maven project should know about its execution directory only, no matter in what context it is executed.

我问了几乎相同的问题:先前用于反应堆根的Maven变量,唯一有意义的答案是使用${user.dir} ,尽管它很hacky,如果您是从模块目录构建的,则将无法正常工作.

I asked almost the same question: Maven variable for reactor root earlier, and the only answer that made sense was to use ${user.dir}, although it's hacky and will not work if you build from a module directory.

(还有一个非常冗长的解决方案: Maven2属性指示父目录)

(There is also this very verbose solution: Maven2 property that indicates the parent directory)

这篇关于Maven $ {basedir}在多模块设置中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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