Maven 离线 - mvn-plugins 问题
我在项目中使用 Maven,并且需要在非互联网访问计算机中运行构建。
当我测试我的项目构建时,一切正常,但是当我在将来的时刻运行构建时,maven 会尝试更新 mvn-plugins 并且这个 sh t* 破坏了我的构建。
我的配置文件:来自 mvn 的settings.xml。
<profile>
<id>blaProfile</id>
<repositories>
<repository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>blaProfile</activeProfile>
</activeProfiles>
我运行我的maven,参数如下:
mvn -npu -bla.3rdParty.home="$(THE_CORRECT_PATH)" package
我看到maven尝试更新一些mvn插件一段时间,但选项:
-npu,--no-plugin-updates Suppress upToDate check for any relevant
应该适用于此更新。
好吧,等待一些帮助!
提前致谢!
UPDATE(1):
What I'm looking at, is that I could use the setting:
<usePluginRegistry>true</usePluginRegistry>
在我的 settings.xml 中,我将在 ${user.home}/.m2 中拥有一个 plugin-registry.xml ,我可以对其进行配置并强制maven 插件版本。
但这不起作用! :(
I'm using maven in my project and I need to run the build in a non-internet-access machine.
When I test my project build everything is working, but when I run the build in a future moment, the maven try to update the mvn-plugins and this sht* is broking my build.
My config file: settings.xml from mvn.
<profile>
<id>blaProfile</id>
<repositories>
<repository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>blaProfile</activeProfile>
</activeProfiles>
And I ran my maven is with the params:
mvn -npu -bla.3rdParty.home="$(THE_CORRECT_PATH)" package
I saw that maven try to update some mvn-plugins for some time, but the option:
-npu,--no-plugin-updates Suppress upToDate check for any relevant
Should work for this updates.
Well waiting some help on that!
Thanks in advance!
UPDATE(1):
What I'm looking at, is that I could use the setting:
<usePluginRegistry>true</usePluginRegistry>
Inside my settings.xml and with this, I'll have a plugin-registry.xml inside ${user.home}/.m2 that I can config and force the maven plugins versions.
But it's not working! :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Maven 离线 + 隔离的 Docker 多阶段镜像构建
我的答案是针对本地构建或 Docker 化环境,后者根据 docker 镜像构建方式的本质进行隔离。 这使用 Maven
3.6.3-jdk-8
。有了这个答案,你就可以准确地知道你的 CI 在下载、编译、测试、打包上花费了多少时间……
最后,也回答一下关于 Jira 下线的老问题 https://issues。 apache.org/jira/browse/MDEP-82?focusedCommentId=16997793&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16997793
pom.xml依赖项
maven-dependency-plugin
surefire-junit-platform
go-offline
解决依赖关系mvn
带开关的命令--off-line
设置插件的最新版本
创建离线缓存
使用 --offline 调用编译
使用 --offline 调用测试
使用 --offline 调用包
最终的运行时映像是来自包的 Docker 映像。
Maven Go-offline + Isolated Docker Multi-stage Image Builds
My answer is for both a local build or a Dockerized environment, which is isolated on the nature of how docker images are built. This uses Maven
3.6.3-jdk-8
.With this answer, you know exactly how much time your CI spends on downloading, compiling, testing, packaging...
Finally, also answering to the old question on Jira for the go-offline https://issues.apache.org/jira/browse/MDEP-82?focusedCommentId=16997793&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16997793
pom.xml
dependenciesmaven-dependency-plugin
surefire-junit-platform
go-offline
resolving dependenciesmvn
command with the switch--off-line
Set latest versions of the plugins
Create the Go-offline cache
Call compile with --offline
Call tests with --offline
Call package with --offline
The final runtime image is a Docker image from the package.
经过一番调试后,我发现
maven-dependency-plugin
(撰写本文时的版本3.1.1
)在指定时无法解析插件的依赖项,如下所示:之后我发现
go-offline-maven-plugin
就可以了! 请参阅 https://github.com/qaware/go-offline-maven-plugin< /a> 了解更多信息。当前版本可以在这里找到 https://mvnrepository.com/ artifact/de.qaware.maven/go-offline-maven-plugin 和 Maven 问题在这里 https://issues.apache.org/jira/browse/MDEP-82
After some debugging I found that
maven-dependency-plugin
(version3.1.1
at the time of writing) is unable to resolve plugin's dependencies when specified like:After that I found
go-offline-maven-plugin
which just works! Pls see https://github.com/qaware/go-offline-maven-plugin for more info.Current version could be found here https://mvnrepository.com/artifact/de.qaware.maven/go-offline-maven-plugin and Maven issue here https://issues.apache.org/jira/browse/MDEP-82
在您的代码上运行
mvn clean install
就足够了。 下次,当您在离线模式下运行它时,您可以使用以下选项:-o
告诉 Maven 不尝试通过网络更新其依赖项,并使用 < code>-Dmaven.repo.local 您提供包含所有必需依赖项的存储库的路径。或者,您可以在 settings.xml 的
localRepository
标记中添加存储库的路径,并添加true
。您可以在 Maven Eclipse 配置中进行相同的配置。
It should suffice to run a
mvn clean install
on your code. The next time, when you run it in an offline mode you can use the following options:-o
tells Maven not to try to update its dependencies over the network and with-Dmaven.repo.local
you provide the path of the repository which contains all the required dependencies.Alternatively, you can add the path of the repository in your settings.xml in the
localRepository
tag and add an<offline>true</offline>
.You can configure the same in your Maven Eclipse configurations.
我认为发生这种情况是因为 Maven 没有在本地获取可用的元数据来确定其插件版本是否正确。 如果您为插件指定了确切的版本(无论如何这对于可重复性来说都是一个好主意),则它不需要进行检查,因此不会尝试连接到远程存储库。
通过指定确切的版本,我的意思是在项目的 POM 中,您应该将版本添加到插件声明中。 例如:
注意,您还可以通过设置存储库镜像来强制 Maven 使用内部存储库而不是中央存储库。 请参阅有关使用存储库管理器和镜像的更多详细信息,请参阅此答案。
在您包含的配置中,您将远程存储库设置为指向本地存储库,这不是一个好主意。 要离线运行,您应该在命令行中传递 -o 或将其添加到您的 settings.xml 中:
I think this happens because Maven hasn't got the metadata available locally to determine if its plugin versions are correct. If you specify exact versions for your plugins (which is a good idea for reproducability anyway), it doesn't need to do the check, so will not try to connect to the remote repositories.
By specify exact versions, I mean that in your project's POM you should add the version to the plugin declaration. For example:
Note you can also force Maven to use internal repositories instead of Central by setting up repository mirrors. See this answer for more details on using repository managers and mirrors.
In the config you included, you're setting your remote repository to point to your local repository, this is not a good idea. To run offline you should either pass -o at the command line or add this to your settings.xml:
在离线之前,运行以下命令:
这会将构建项目所需的所有依赖项和插件下载到 ~/.m2/repository 中。
运行后,您现在可以使用“-o”标志离线构建项目:
Before you go offline run the following:
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
为了将插件缓存到 .m2/repository 文件夹中,您需要使用
mvn:help
显式指定所有插件,您还需要为每个插件指定显式版本pom.xml 的
或
部分中的插件这需要确保
mvn install -o
使用相同的插件版本。当然,您还需要运行 mvn dependency:go-offline 来处理编译和测试依赖项。
mvn assembly:帮助编译器:帮助执行者:帮助执行者:帮助failsafe:帮助安装:帮助jar:帮助资源:帮助surefire:帮助
mvn 依赖:脱机
mvn 编译 --offline
In order to cache plugins into the .m2/repository folder you would need to specify all plugins explicitly with the
mvn <maven-plugin-name>:help
You would also need to specify explicit version for each plugin in the
<plugins>
or<pluginsManagement>
section of your pom.xmlThis is needed to make sure that
mvn install -o
uses the same plugin version.Ofcourse you would also need to run
mvn dependency:go-offline
to take care of your compile and test dependencies.mvn assembly:help compiler:help enforcer:help exec:help failsafe:help install:help jar:help resources:help surefire:help
mvn dependency:go-offline
mvn compile --offline