如何配置Maven进行离线开发?

时间:2022-09-03 19:50:25

Does maven require a connection to the internet at some point to be able to use it? Meaning specifically getting the internal maven plugins for compiling, cleaning, packaging, etc?

maven是否需要在某些时候连接到互联网才能使用它?具体意义是获取用于编译,清洁,包装等的内部maven插件?

12 个解决方案

#1


132  

You can run maven in offline mode mvn -o install. Of course any artifacts not available in your local repository will fail. Maven is not predicated on distributed repositories, but they certainly make things more seamless. Its for this reason that many shops use internal mirrors that are incrementally synced with the central repos.

您可以在离线模式mvn -o install中运行maven。当然,本地存储库中没有的任何工件都将失败。 Maven不依赖于分布式存储库,但它们确实使事情更加无缝。由于这个原因,许多商店使用内部镜子,与*回购逐步同步。

In addition, the mvn dependency:go-offline can be used to ensure you have all of your dependencies installed locally before you begin to work offline.

此外,mvn依赖项:go-offline可用于确保在开始脱机工作之前已在本地安装所有依赖项。

#2


10  

If you have a PC with internet access in your LAN, you should install a local Maven repository.

如果您的LAN中有可以访问Internet的PC,则应安装本地Maven存储库。

I recommend Artifactory Open Source. This is what we use in our organization, it is really easy to setup.

我推荐Artifactory Open Source。这是我们在组织中使用的,它很容易设置。

Artifactory acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle etc.) and the outside world.

Artifactory充当您的构建工具(Maven,Ant,Ivy,Gradle等)与外部世界之间的代理。

It caches remote artifacts so that you don’t have to download them over and over again.

它会缓存远程工件,因此您无需一遍又一遍地下载它们。

It blocks unwanted (and sometimes security-sensitive) external requests for internal artifacts and controls how and where artifacts are deployed, and by whom.

它阻止对内部工件的不需要的(有时是安全敏感的)外部请求,并控制工件的部署方式和位置,以及由谁控制。

After setting up Artifactory you just need to change Maven's settings.xml in the development machines:

设置Artifactory之后,您只需要在开发机器中更改Maven的settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>repo</name>
      <url>http://maven.yourorganization.com:8081/artifactory/repo</url>
      <id>repo</id>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://maven.yourorganization.com:8081/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://maven.yourorganization.com:8081/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>plugins-release</name>
          <url>http://maven.yourorganization.com:8081/artifactory/plugins-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>plugins-snapshot</name>
          <url>http://maven.yourorganization.com:8081/artifactory/plugins-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

We used this solution because we had problems with internet access in our development machines and some artifacts downloaded corrupted files or didn't download at all. We haven't had problems since.

我们使用此解决方案是因为我们的开发机器中存在Internet访问问题,而某些工件下载了损坏的文件或根本没有下载。从那时起我们就没有遇到过问题

#3


7  

You have two options for this:

你有两个选择:

1.) make changes in the settings.xml add this in first tag

1.)在settings.xml中进行更改,将其添加到第一个标记中

<localRepository>C:/Users/admin/.m2/repository</localRepository>

2.) use the -o tag for offline command.

2.)使用-o标签进行离线命令。

mvn -o clean install -DskipTests=true
mvn -o jetty:run

#4


6  

Maven needs the dependencies in your local repository. The easiest way to get them is with internet access (or harder using other solutions provided here).

Maven需要本地存储库中的依赖项。获得它们的最简单方法是使用互联网访问(或使用此处提供的其他解决方案更难)。

So assumed that you can get temporarily internet access you can prepare to go offline using the maven-dependency-plugin with its dependency:go-offline goal. This will download all your project dependencies to your local repository (of course changes in the dependencies / plugins will require new internet / central repository access).

因此,假设您可以临时访问Internet,您可以使用maven-dependency-plugin及其依赖项准备脱机:脱机目标。这会将所有项目依赖项下载到本地存储库(当然,依赖项/插件中的更改将需要新的Internet /*存储库访问)。

#5


4  

Sadly dependency:go-offline hasn't worked for me as it didn't cached everything, ie. POMs files and other implicitly mention dependencies.

可悲的依赖:go-offline对我没有用,因为它没有缓存所有内容,即。 POM文件和其他隐式提及依赖项。

The workaround has been to specify a local repository location, either within settings.xml file with <localRepository>...</localRepository> or by running mvn with -Dmaven.repo.local=... parameter. After initial project build, all necessary artifacts should be cached, and then you can reference repository location the same ways, while running Maven build in offline mode (mvn -o ...).

解决方法是在带有 ... 的settings.xml文件中指定本地存储库位置,或者使用-Dmaven.repo.local = ...参数运行mvn。在初始项目构建之后,应该缓存所有必需的工件,然后您可以以相同的方式引用存储库位置,同时在脱机模式下运行Maven构建(mvn -o ...)。

#6


2  

Does this work for you?

这对你有用吗?

http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html

http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html

Don't forget to add it to your plugin repository and point the url to wherever your repository is.

不要忘记将它添加到您的插件存储库并将URL指向您的存储库所在的位置。

<repositories>
    <repository>
        <id>local</id>
        <url>file://D:\mavenrepo</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>local</id>
        <url>file://D:\mavenrepo</url>
    </pluginRepository>
</pluginRepositories>

If not, you may need to run a local server, e.g. apache, on your machines.

如果没有,您可能需要运行本地服务器,例如阿帕奇,在你的机器上。

#7


2  

如何配置Maven进行离线开发?

or

要么

如何配置Maven进行离线开发?

Just use Maven repository servers like Sonatype Nexus http://www.sonatype.org/nexus/ or JFrog Artifactory https://www.jfrog.com/artifactory/.

只需使用Maven存储库服务器,如Sonatype Nexus http://www.sonatype.org/nexus/或JFrog Artifactory https://www.jfrog.com/artifactory/。

After one developer builds a project, build by next developers or Jenkins CI will not require Internet access.

在一个开发人员构建项目之后,由下一个开发人员或Jenkins CI构建将不需要Internet访问。

Maven repository server also can have proxies configured to access Maven Central (or more needed public repositories), and they can have cynch'ed list of artifacts in remote repositories.

Maven存储库服务器还可以配置代理以访问Maven Central(或更需要的公共存储库),并且它们可以在远程存储库中具有cynch的工件列表。

#8


2  

Before going offline you have to make sure that everything is in your local repo, which is required while working offline. Running "mvn dependency:go-offline" for the project(s)/pom(s), you intend to work on, will reduce the efforts to achieve this.

在离线之前,您必须确保所有内容都在您的本地仓库中,这在离线工作时是必需的。对于项目/ pom(s)运行“mvn dependency:go-offline”,您打算继续工作,将减少实现这一目标的努力。

But it´s usually not the whole story, because dependency:go-offline will only download the "bare build" plugins (go-offline / resolve-plugins does not resolve all plugin dependencies). So you have to find a way to download deploy / test / site plugins (and maybe others) and their dependencies into your repo.

但它通常不是整个故事,因为依赖:go-offline只会下载“裸构建”插件(go-offline / resolve-plugins不会解析所有插件依赖项)。因此,您必须找到一种方法将部署/测试/站点插件(可能还有其他)及其依赖项下载到您的仓库中。

Furthermore dependency:go-offline does not download the pom´s artifact itself, so you have to dependency:copy it if required.

此外,依赖:go-offline不会下载pom的工件本身,因此你必须依赖:如果需要,复制它。

Sometimes - as MaDa wrote - you do not know, what you will need, while being offline, which makes it pretty impossible to have a "sufficient" repo.

有时候 - 正如MaDa写的那样 - 你不知道,在离线的时候你需要什么,这使得很难拥有一个“充足”的回购。

Anyway having a properly filled repo you only have to add "<offline>true</offline>" to Maven´s settings.xml to go offline.

无论如何都有一个正确填充的repo你只需要在Maven的settings.xml中添加“ true ”即可离线。

Do not change the Maven profile (id) you used to fill your repo, while being offline. Maven recognizes the downloaded artifacts in its metadata with an "identity", which is bound to the profile id.

在离线时,请勿更改用于填充回购的Maven个人资料(id)。 Maven使用“身份”识别其元数据中的下载工件,该身份绑定到配置文件ID。

#9


1  

If you're using IntelliJ, you can simply go to Preferences -> Build, Execution, Deployment -> Build Tools -> Maven and check/uncheck Work offline.

如果您正在使用IntelliJ,您只需转到首选项 - >构建,执行,部署 - >构建工具 - > Maven,然后选中/取消选中离线工作。

#10


0  

Answering your question directly: it does not require an internet connection, but access to a repository, on LAN or local disk (use hints from other people who posted here).

直接回答您的问题:它不需要互联网连接,而是访问存储库,局域网或本地磁盘(使用此处发布的其他人的提示)。

If your project is not in a mature phase, that means when POMs are changed quite often, offline mode will be very impractical, as you'll have to update your repository quite often, too. Unless you can get a copy of a repository that has everything you need, but how would you know? Usually you start a repository from scratch and it gets cloned gradually during development (on a computer connected to another repository). A copy of the repo1.maven.org public repository weighs hundreds of gigabytes, so I wouldn't recommend brute force, either.

如果您的项目尚未处于成熟阶段,这意味着当POM经常更改时,离线模式将非常不切实际,因为您还必须经常更新您的存储库。除非您能获得包含所需内容的存储库副本,但您怎么知道?通常,您从头开始创建存储库,并在开发过程中逐渐克隆(在连接到另一个存储库的计算机上)。 repo1.maven.org公共存储库的副本重达数百GB,因此我也不建议使用暴力破解程序。

#11


0  

In preparation before working offline just run mvn dependency:go-offline

在离线工作之前的准备工作中,只需运行mvn dependency:go-offline

#12


0  

My experience shows that the -o option doesn't work properly and that the go-offline goal is far from sufficient to allow a full offline build:

我的经验表明-o选项无法正常运行,并且离线目标远远不足以允许完整的脱机构建:

The solution I could validate includes the use of the --legacy-local-repository maven option rather than the -o (offline) one and the use of the local repository in place of the distribution repository

我可以验证的解决方案包括使用--legacy-local-repository maven选项而不是-o(离线)选项以及使用本地存储库代替分发存储库

In addition, I had to copy every maven-metadata-maven2_central.xml files of the local-repo into the maven-metadata.xml form expected by maven.

另外,我不得不将local-repo的每个maven-metadata-maven2_central.xml文件复制到maven期望的maven-metadata.xml表单中。

See the solution I found here.

看到我在这里找到的解决方案。

#1


132  

You can run maven in offline mode mvn -o install. Of course any artifacts not available in your local repository will fail. Maven is not predicated on distributed repositories, but they certainly make things more seamless. Its for this reason that many shops use internal mirrors that are incrementally synced with the central repos.

您可以在离线模式mvn -o install中运行maven。当然,本地存储库中没有的任何工件都将失败。 Maven不依赖于分布式存储库,但它们确实使事情更加无缝。由于这个原因,许多商店使用内部镜子,与*回购逐步同步。

In addition, the mvn dependency:go-offline can be used to ensure you have all of your dependencies installed locally before you begin to work offline.

此外,mvn依赖项:go-offline可用于确保在开始脱机工作之前已在本地安装所有依赖项。

#2


10  

If you have a PC with internet access in your LAN, you should install a local Maven repository.

如果您的LAN中有可以访问Internet的PC,则应安装本地Maven存储库。

I recommend Artifactory Open Source. This is what we use in our organization, it is really easy to setup.

我推荐Artifactory Open Source。这是我们在组织中使用的,它很容易设置。

Artifactory acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle etc.) and the outside world.

Artifactory充当您的构建工具(Maven,Ant,Ivy,Gradle等)与外部世界之间的代理。

It caches remote artifacts so that you don’t have to download them over and over again.

它会缓存远程工件,因此您无需一遍又一遍地下载它们。

It blocks unwanted (and sometimes security-sensitive) external requests for internal artifacts and controls how and where artifacts are deployed, and by whom.

它阻止对内部工件的不需要的(有时是安全敏感的)外部请求,并控制工件的部署方式和位置,以及由谁控制。

After setting up Artifactory you just need to change Maven's settings.xml in the development machines:

设置Artifactory之后,您只需要在开发机器中更改Maven的settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>repo</name>
      <url>http://maven.yourorganization.com:8081/artifactory/repo</url>
      <id>repo</id>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://maven.yourorganization.com:8081/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://maven.yourorganization.com:8081/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>plugins-release</name>
          <url>http://maven.yourorganization.com:8081/artifactory/plugins-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>plugins-snapshot</name>
          <url>http://maven.yourorganization.com:8081/artifactory/plugins-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

We used this solution because we had problems with internet access in our development machines and some artifacts downloaded corrupted files or didn't download at all. We haven't had problems since.

我们使用此解决方案是因为我们的开发机器中存在Internet访问问题,而某些工件下载了损坏的文件或根本没有下载。从那时起我们就没有遇到过问题

#3


7  

You have two options for this:

你有两个选择:

1.) make changes in the settings.xml add this in first tag

1.)在settings.xml中进行更改,将其添加到第一个标记中

<localRepository>C:/Users/admin/.m2/repository</localRepository>

2.) use the -o tag for offline command.

2.)使用-o标签进行离线命令。

mvn -o clean install -DskipTests=true
mvn -o jetty:run

#4


6  

Maven needs the dependencies in your local repository. The easiest way to get them is with internet access (or harder using other solutions provided here).

Maven需要本地存储库中的依赖项。获得它们的最简单方法是使用互联网访问(或使用此处提供的其他解决方案更难)。

So assumed that you can get temporarily internet access you can prepare to go offline using the maven-dependency-plugin with its dependency:go-offline goal. This will download all your project dependencies to your local repository (of course changes in the dependencies / plugins will require new internet / central repository access).

因此,假设您可以临时访问Internet,您可以使用maven-dependency-plugin及其依赖项准备脱机:脱机目标。这会将所有项目依赖项下载到本地存储库(当然,依赖项/插件中的更改将需要新的Internet /*存储库访问)。

#5


4  

Sadly dependency:go-offline hasn't worked for me as it didn't cached everything, ie. POMs files and other implicitly mention dependencies.

可悲的依赖:go-offline对我没有用,因为它没有缓存所有内容,即。 POM文件和其他隐式提及依赖项。

The workaround has been to specify a local repository location, either within settings.xml file with <localRepository>...</localRepository> or by running mvn with -Dmaven.repo.local=... parameter. After initial project build, all necessary artifacts should be cached, and then you can reference repository location the same ways, while running Maven build in offline mode (mvn -o ...).

解决方法是在带有 ... 的settings.xml文件中指定本地存储库位置,或者使用-Dmaven.repo.local = ...参数运行mvn。在初始项目构建之后,应该缓存所有必需的工件,然后您可以以相同的方式引用存储库位置,同时在脱机模式下运行Maven构建(mvn -o ...)。

#6


2  

Does this work for you?

这对你有用吗?

http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html

http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html

Don't forget to add it to your plugin repository and point the url to wherever your repository is.

不要忘记将它添加到您的插件存储库并将URL指向您的存储库所在的位置。

<repositories>
    <repository>
        <id>local</id>
        <url>file://D:\mavenrepo</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>local</id>
        <url>file://D:\mavenrepo</url>
    </pluginRepository>
</pluginRepositories>

If not, you may need to run a local server, e.g. apache, on your machines.

如果没有,您可能需要运行本地服务器,例如阿帕奇,在你的机器上。

#7


2  

如何配置Maven进行离线开发?

or

要么

如何配置Maven进行离线开发?

Just use Maven repository servers like Sonatype Nexus http://www.sonatype.org/nexus/ or JFrog Artifactory https://www.jfrog.com/artifactory/.

只需使用Maven存储库服务器,如Sonatype Nexus http://www.sonatype.org/nexus/或JFrog Artifactory https://www.jfrog.com/artifactory/。

After one developer builds a project, build by next developers or Jenkins CI will not require Internet access.

在一个开发人员构建项目之后,由下一个开发人员或Jenkins CI构建将不需要Internet访问。

Maven repository server also can have proxies configured to access Maven Central (or more needed public repositories), and they can have cynch'ed list of artifacts in remote repositories.

Maven存储库服务器还可以配置代理以访问Maven Central(或更需要的公共存储库),并且它们可以在远程存储库中具有cynch的工件列表。

#8


2  

Before going offline you have to make sure that everything is in your local repo, which is required while working offline. Running "mvn dependency:go-offline" for the project(s)/pom(s), you intend to work on, will reduce the efforts to achieve this.

在离线之前,您必须确保所有内容都在您的本地仓库中,这在离线工作时是必需的。对于项目/ pom(s)运行“mvn dependency:go-offline”,您打算继续工作,将减少实现这一目标的努力。

But it´s usually not the whole story, because dependency:go-offline will only download the "bare build" plugins (go-offline / resolve-plugins does not resolve all plugin dependencies). So you have to find a way to download deploy / test / site plugins (and maybe others) and their dependencies into your repo.

但它通常不是整个故事,因为依赖:go-offline只会下载“裸构建”插件(go-offline / resolve-plugins不会解析所有插件依赖项)。因此,您必须找到一种方法将部署/测试/站点插件(可能还有其他)及其依赖项下载到您的仓库中。

Furthermore dependency:go-offline does not download the pom´s artifact itself, so you have to dependency:copy it if required.

此外,依赖:go-offline不会下载pom的工件本身,因此你必须依赖:如果需要,复制它。

Sometimes - as MaDa wrote - you do not know, what you will need, while being offline, which makes it pretty impossible to have a "sufficient" repo.

有时候 - 正如MaDa写的那样 - 你不知道,在离线的时候你需要什么,这使得很难拥有一个“充足”的回购。

Anyway having a properly filled repo you only have to add "<offline>true</offline>" to Maven´s settings.xml to go offline.

无论如何都有一个正确填充的repo你只需要在Maven的settings.xml中添加“ true ”即可离线。

Do not change the Maven profile (id) you used to fill your repo, while being offline. Maven recognizes the downloaded artifacts in its metadata with an "identity", which is bound to the profile id.

在离线时,请勿更改用于填充回购的Maven个人资料(id)。 Maven使用“身份”识别其元数据中的下载工件,该身份绑定到配置文件ID。

#9


1  

If you're using IntelliJ, you can simply go to Preferences -> Build, Execution, Deployment -> Build Tools -> Maven and check/uncheck Work offline.

如果您正在使用IntelliJ,您只需转到首选项 - >构建,执行,部署 - >构建工具 - > Maven,然后选中/取消选中离线工作。

#10


0  

Answering your question directly: it does not require an internet connection, but access to a repository, on LAN or local disk (use hints from other people who posted here).

直接回答您的问题:它不需要互联网连接,而是访问存储库,局域网或本地磁盘(使用此处发布的其他人的提示)。

If your project is not in a mature phase, that means when POMs are changed quite often, offline mode will be very impractical, as you'll have to update your repository quite often, too. Unless you can get a copy of a repository that has everything you need, but how would you know? Usually you start a repository from scratch and it gets cloned gradually during development (on a computer connected to another repository). A copy of the repo1.maven.org public repository weighs hundreds of gigabytes, so I wouldn't recommend brute force, either.

如果您的项目尚未处于成熟阶段,这意味着当POM经常更改时,离线模式将非常不切实际,因为您还必须经常更新您的存储库。除非您能获得包含所需内容的存储库副本,但您怎么知道?通常,您从头开始创建存储库,并在开发过程中逐渐克隆(在连接到另一个存储库的计算机上)。 repo1.maven.org公共存储库的副本重达数百GB,因此我也不建议使用暴力破解程序。

#11


0  

In preparation before working offline just run mvn dependency:go-offline

在离线工作之前的准备工作中,只需运行mvn dependency:go-offline

#12


0  

My experience shows that the -o option doesn't work properly and that the go-offline goal is far from sufficient to allow a full offline build:

我的经验表明-o选项无法正常运行,并且离线目标远远不足以允许完整的脱机构建:

The solution I could validate includes the use of the --legacy-local-repository maven option rather than the -o (offline) one and the use of the local repository in place of the distribution repository

我可以验证的解决方案包括使用--legacy-local-repository maven选项而不是-o(离线)选项以及使用本地存储库代替分发存储库

In addition, I had to copy every maven-metadata-maven2_central.xml files of the local-repo into the maven-metadata.xml form expected by maven.

另外,我不得不将local-repo的每个maven-metadata-maven2_central.xml文件复制到maven期望的maven-metadata.xml表单中。

See the solution I found here.

看到我在这里找到的解决方案。