如果我已经在仓库中安装了这个版本,如何跳过 Maven 构建中的安装阶段
我有一个由 3 个不同的库组成的项目。当我运行安装脚本时,它会从存储库中获取所有库并对其运行 mvn clean install 。但这个版本的库已经安装在仓库中。如果 pom.xml 中的版本与我本地存储库中的版本相同,有没有办法跳过安装阶段。
我知道我可以使用本地存储库并只需设置依赖项。但我的老板希望我们的项目只能使用公共回购来构建,而不需要任何我们的回购。
I have a project that consist of 3 different libraries. When I run install script it takes all libraries from repo and run mvn clean install on them. But this version of library already installed in repo. Is there a way to skip install phase if version in pom.xml equal version in my local repo.
I know that I can use local repo and just set dependencies. But my boss want that our project can build only with public repos and without any our repos.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
你可以像这样绕过
上周 Olivier Lamy 修补了这个 jira。
MINSTALL-73
You can bypass like this
Last week Olivier Lamy patched this jira.
MINSTALL-73
大多数 Maven 插件可以通过指定类似的内容来跳过:
您还可以设置构建配置文件来设置属性并使用它来确定值。例如,运行命令: mvn -Pexample 将选择“example”配置文件。然后,POM 将包含:
使用这些 POM 添加,安装插件的默认行为将是执行其默认目标,但如果选择了示例配置文件,则安装插件将跳过其目标。
Most maven plugins can be skipped by specifying something like:
you can also set up build profiles to set properties and use that to determine the value. for example, running the command: mvn -Pexample would select the "example" profile. The POM would then contain:
Using these POM additions, the default behavior for the install plugin will be to perform its default goal, but if the example profile is selected, then the install plugin will skip its goal.
根据我从其他答案中学到的知识,这对我来说是最干净的结果。
在我的超级 pom 中,我添加了一个pluginManagement/plugin,以在设置属性
deployOnly
时禁用默认安装和默认测试阶段。因此,在命令行上,我可以通过添加 -DdeployOnly 来禁用安装和测试阶段。
Using what I learned from the other answers, this was the cleanest result for me.
In my super pom I added a pluginManagement/plugin to disable default-install and default-test phases when the property
deployOnly
is set.So on the command line, I can disable install and test phases by adding
-DdeployOnly
.你确定你正确理解了老板的意思吗?我将上述内容解释为“不要在本地存储库中安装第三方库,仅使用公共存储库中可用的库”。这与“不使用本地存储库”不同,后者基本上是不可能的,这不是 Maven 的工作方式。我想尝试澄清这一点。
除此之外,我没有得到一个非常令人困惑的问题(你在说什么存储库?安装脚本在做什么?为什么你在库上调用干净安装?等等)。
Are you sure you understood correctly what you boss meant? I interpret the above as "don't install third party libraries in your local repository, use only libraries available in public repositories". This is different from "don't use your local repository" which is basically impossible, that's just not how maven works. I'd try to clarify this point.
Apart from that, I don't get the question which is very confusing (what repo are you talking about? What is the install script doing? Why do you call clean install on libraries? etc).
从未来扩展其他答案。
Maven 插件有惊人的高自由度,它们如何运行。如果他们愿意,他们可以忽略/覆盖典型的 pom.xml 设置。此外,
true
也只是一个约定,没有什么强制插件遵循它,除了大多数插件都是这样开发的。我对最近问题的实验表明,@Cemo 和 @MiloshBoroyevich 解决方案都应该使用,而且该插件需要两者才能真正让我们安心。更具体地说,我唯一有效的配置是:
Extending the other answers, from the future.
Maven plugins have a surprisingly high freedom, how do they run. If they want, they can ignore/override the typical pom.xml settings. Furthermore, also the
<configuration><skip>true</skip></configuration>
is only a convention, nothing obligates a plugin to follow it, except that most of them is developed so.My experiments with the recent problem show, that both @Cemo's and @MiloshBoroyevich solution should be utilized, also the plugin requires both to really let us in peace. More concretely, the only working configuration by me was this:
您的选择之一是将部署放入另一个模块。即,使用一个
pom.xml
构建工件并将其安装到本地存储库,并使用另一个pom.xml
来部署它。这种分离在较大的项目中很常见,其中测试套件有时是一个单独的模块甚至是一个项目,打包分几个阶段进行,等等。One of your options is to put the deployment to another module. I.e. have one
pom.xml
build the artifact and install it to the local repo, and anotherpom.xml
to deploy it. This separation is quite common in larger projects, where the testsuite is sometimes a separate module or even a project, the packaging happens in several stages, etc.以避免安装阶段
to avoid install phase