I'm using maven in my project and I need to run the build in a non-internet-access machine.
我在我的项目中使用maven,我需要在非internet访问机器上运行构建。
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.
当我测试我的项目构建时,一切都在工作,但是当我在将来运行构建时,maven会尝试更新mvn-plugin,而这个sht*是我的构建。
My config file: settings.xml from mvn.
我的配置文件设置。从mvn 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>
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:
我看到maven在一段时间内试图更新一些mvc插件,但是有以下选项:
-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! :(
在我的设置。有了这个xml,我就有了一个插件注册表。xml在$ { user.home } /。我可以配置并强制maven插件版本的m2。但它不是工作!:(
4 个解决方案
#1
6
Before you go offline run the following:
在您脱机之前,请执行以下操作:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
这将下载您需要将项目构建到~/.m2/存储库中的所有依赖项和插件。
Once you've run that you can now build your project offline using the '-o' flag:
运行之后,现在可以使用“-o”标志离线构建项目:
mvn install -o
#2
2
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
为了将插件缓存到.m2/repository文件夹中,您需要明确地使用mvn
You would also need to specify explicit version for each plugin in the <plugins>
or <pluginsManagement>
section of your pom.xml
您还需要在您的pom.xml的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
</plugin>
This is needed to make sure that mvn install -o
uses the same plugin version.
这需要确保mvn安装-o使用相同的插件版本。
Ofcourse you would also need to run mvn dependency:go-offline
to take care of your compile and test dependencies.
当然,您还需要运行mvn依赖项:go-offline,以处理编译和测试依赖项。
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
汇编:帮助编译器:帮助执行器:帮助执行器:帮助失败安全:帮助安装:帮助jar:帮助资源:帮助保证:帮助mvn依赖:go-offline mvn编译——脱机
#3
1
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:
在代码上运行mvn清理安装就足够了。下一次,当您在离线模式下运行时,您可以使用以下选项:
mvn -Dmaven.repo.local=..\repository –o clean install
-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.
-o告诉maven不要试图通过网络和-Dmaven.repo更新它的依赖关系。local提供包含所有所需依赖项的存储库的路径。或者,您可以在设置中添加存储库的路径。在localRepository标签中的xml并添加一个 <脱机> true 。您可以在Maven Eclipse配置中配置相同的内容。
#4
0
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.
我认为这是因为Maven没有本地可用的元数据来确定其插件版本是否正确。如果您为您的插件指定了确切的版本(无论如何,这对可再生性来说是一个好主意),那么它不需要进行检查,因此不会尝试连接到远程存储库。
By specify exact versions, I mean that in your project's POM you should add the version to the plugin declaration. For example:
通过指定确切的版本,我的意思是在项目的POM中,您应该将版本添加到插件声明中。例如:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- set the version explicitly-->
<version>2.0</version>
</plugin>
</plugins>
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.
注意,还可以通过设置存储库镜像来强制Maven使用内部存储库,而不是使用中心存储库。有关使用存储库管理器和镜像的更多细节,请参见此答案。
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:
在包含的配置中,将远程存储库设置为指向本地存储库,这不是一个好主意。要脱机运行,您应该在命令行中传递-o,或将其添加到您的settings.xml中:
<offline>true</offline>
#1
6
Before you go offline run the following:
在您脱机之前,请执行以下操作:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
这将下载您需要将项目构建到~/.m2/存储库中的所有依赖项和插件。
Once you've run that you can now build your project offline using the '-o' flag:
运行之后,现在可以使用“-o”标志离线构建项目:
mvn install -o
#2
2
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
为了将插件缓存到.m2/repository文件夹中,您需要明确地使用mvn
You would also need to specify explicit version for each plugin in the <plugins>
or <pluginsManagement>
section of your pom.xml
您还需要在您的pom.xml的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
</plugin>
This is needed to make sure that mvn install -o
uses the same plugin version.
这需要确保mvn安装-o使用相同的插件版本。
Ofcourse you would also need to run mvn dependency:go-offline
to take care of your compile and test dependencies.
当然,您还需要运行mvn依赖项:go-offline,以处理编译和测试依赖项。
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
汇编:帮助编译器:帮助执行器:帮助执行器:帮助失败安全:帮助安装:帮助jar:帮助资源:帮助保证:帮助mvn依赖:go-offline mvn编译——脱机
#3
1
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:
在代码上运行mvn清理安装就足够了。下一次,当您在离线模式下运行时,您可以使用以下选项:
mvn -Dmaven.repo.local=..\repository –o clean install
-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.
-o告诉maven不要试图通过网络和-Dmaven.repo更新它的依赖关系。local提供包含所有所需依赖项的存储库的路径。或者,您可以在设置中添加存储库的路径。在localRepository标签中的xml并添加一个 <脱机> true 。您可以在Maven Eclipse配置中配置相同的内容。
#4
0
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.
我认为这是因为Maven没有本地可用的元数据来确定其插件版本是否正确。如果您为您的插件指定了确切的版本(无论如何,这对可再生性来说是一个好主意),那么它不需要进行检查,因此不会尝试连接到远程存储库。
By specify exact versions, I mean that in your project's POM you should add the version to the plugin declaration. For example:
通过指定确切的版本,我的意思是在项目的POM中,您应该将版本添加到插件声明中。例如:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- set the version explicitly-->
<version>2.0</version>
</plugin>
</plugins>
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.
注意,还可以通过设置存储库镜像来强制Maven使用内部存储库,而不是使用中心存储库。有关使用存储库管理器和镜像的更多细节,请参见此答案。
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:
在包含的配置中,将远程存储库设置为指向本地存储库,这不是一个好主意。要脱机运行,您应该在命令行中传递-o,或将其添加到您的settings.xml中:
<offline>true</offline>