简体   繁体   English

Maven 不使用本地存储库

[英]Maven not using local repository

I have a small problem with my Maven config.我的 Maven 配置有一个小问题。 All other questions and answers here didn't solve my problem, so I'm starting a new question.这里的所有其他问题和答案都没有解决我的问题,所以我开始提出一个新问题。

My problem is, that my Maven is not using the local repository.我的问题是,我的 Maven 没有使用本地存储库。 It's always fetching the artifacts from the remote repositories.它总是从远程存储库中获取工件。

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).问题是:当我构建一个SNAPSHOT项目时,它只安装在本地存储库中(应该是这样,不想每次都发布在我的nexus上)。 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.当我在 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!感谢您的帮助!

You've configured that the SNAPSHOTs should always ( <updatePolicy>always</updatePolicy> ) be downloaded from your snapshot-nexus.您已配置应始终<updatePolicy>always</updatePolicy> )从您的快照连接下载 SNAPSHOT。 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 ).因此,即使您的本地缓存( ~/.m2/repository )具有更新版本的快照,maven 也会尝试从配置的服务器( http://nexus/content/repositories/snapshots )下载它。

Think about changing the updatePolicy for the snapshot-entry.考虑更改快照条目的 updatePolicy。 Eg if you have a CI-server which deploys a SNAPSHOT daily (in the morning) to the snapshot-nexus, change the updatePolicy to daily .例如,如果您有一个 CI 服务器,它每天(早上)将 SNAPSHOT 部署到快照关系,请将 updatePolicy 更改为daily

If you change you'r config to <updatePolicy>always</updatePolicy> , it still will attempts to download from the nexus, because you have to disable nexus config in pom.xml如果您将配置更改为<updatePolicy>always</updatePolicy> ,它仍然会尝试从 nexus 下载,因为您必须在pom.xml禁用 nexus 配置
mind that <reposotiry> tag in your pom.xml will take precedence over what's defined in your settings.xml请注意pom.xml中的<reposotiry>标记将优先于settings.xml定义的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM