Maven offline - problem with mvn-plugins

妖精的绣舞 提交于 2019-12-01 05:57:19

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.

Once you've run that you can now build your project offline using the '-o' flag:

mvn install -o
itaifrenkel

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

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

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

Rich Seller

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:

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

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:

<offline>true</offline>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!