Java Maven 不使用本地存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19180696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:48:59  来源:igfitidea点击:

Maven not using local repository

javamavennexus

提问by virtualmarc

I have a small problem with my Maven config. All other questions and answers here didn't solve my problem, so I'm starting a new question.

我的 Maven 配置有一个小问题。这里的所有其他问题和答案都没有解决我的问题,所以我开始提出一个新问题。

My problem is, that my Maven is not using the local repository. It's always fetching the artifacts from the remote repositories.

我的问题是,我的 Maven 没有使用本地存储库。它总是从远程存储库中获取工件。

When an artifact is downloaded or when I build a project it is installed in the local repository, so the path is correct.

下载工件或构建项目时,它会安装在本地存储库中,因此路径是正确的。

The problem is: When I build one SNAPSHOT project, it is only installed in the local repository (should be like this, don't want to publish it on my nexus every time). When I build another project having the previous one as dependency in the pom.xml maven wants to download the artifact from the nexus server where it didn't find it instead of taking it from the local repository.

问题是:当我构建一个SNAPSHOT项目时,它只安装在本地存储库中(应该是这样,不想每次都发布在我的nexus上)。当我在 pom.xml 中构建另一个项目作为依赖项时,maven 想要从它没有找到它的 nexus 服务器下载工件,而不是从本地存储库中获取它。

This is my maven config:

这是我的 Maven 配置:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>C:\Users\Marc\.m2\repository</localRepository>
  <interactiveMode>false</interactiveMode>
  <usePluginRegistry>false</usePluginRegistry>
  <pluginGroups>
  </pluginGroups>
  <servers>
    <server>
      <id>releases</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
    <server>
      <id>snapshots</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
    <server>
      <id>nexus</id>
      <username>MY_USERNAME</username>
      <password>MY_PASSWORD</password>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>nexussrv</id>
      <repositories>
        <repository>
          <id>snapshots</id>
          <url>http://nexus/content/repositories/snapshots</url>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
          <releases>
            <enabled>false</enabled>
          </releases>
        </repository>
        <repository>
          <id>releases</id>
          <url>http://nexus/content/repositories/releases</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>nexus</id>
          <url>http://nexus/content/groups/public</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexussrv</activeProfile>
  </activeProfiles>
</settings>

Downloading from the nexus and publishing artifacts (SNAPSHOT and RELEASE) to the nexus work with this config but it doesn't use artifacts from the local repository.

从 nexus 下载和发布工件(SNAPSHOT 和 RELEASE)到 nexus 可以使用此配置,但它不使用本地存储库中的工件。

Thanks for your Help!

感谢您的帮助!

采纳答案by MrD

You've configured that the SNAPSHOTs should always(<updatePolicy>always</updatePolicy>) be downloaded from your snapshot-nexus. So even if your local cache (the ~/.m2/repository) has a newer version of the snapshot, maven tries to download it from the configured server (http://nexus/content/repositories/snapshots).

您已配置 SNAPSHOT 应始终( <updatePolicy>always</updatePolicy>) 从您的快照关系下载。因此,即使您的本地缓存 (the ~/.m2/repository) 具有更新版本的快照,maven也会尝试从配置的服务器 ( http://nexus/content/repositories/snapshots)下载它。

Think about changing the updatePolicy for the snapshot-entry. E.g. if you have a CI-server which deploys a SNAPSHOT daily (in the morning) to the snapshot-nexus, change the updatePolicy to daily.

考虑更改快照条目的 updatePolicy。例如,如果您有一个 CI 服务器,它每天(早上)将 SNAPSHOT 部署到快照关系,请将 updatePolicy 更改为daily.