简体   繁体   English

Maven 忽略本地存储库

[英]Maven ignores local repository

I'm trying to use jackson at a json project.我正在尝试在 json 项目中使用 jackson。 And Maven is ignoring my local repository (where I have the library already set, from a previous project) and downloading from codehaus repo. Maven 忽略了我的本地存储库(我已经从以前的项目中设置了库)并从 codehaus 存储库下载。

The catch is that my workplace has blocked access to external repos, so I must use local repository for this.问题是我的工作场所阻止了对外部存储库的访问,因此我必须为此使用本地存储库。 How do I force Maven to look first at local and use the library there?如何强制 Maven 首先查看本地并使用那里的库?

Thanks in advance提前致谢

Please set the Local Repository Path in eclipse that maps to your local repo path..请在 eclipse 中设置映射到本地存储库路径的本地存储库路径..

Go to Windows->Preferences->Maven->User Settings and change the settings.xml and your local repository path..转到Windows->Preferences->Maven->User Settings并更改 settings.xml 和您的本地存储库路径..

If these both are correctly located then it should check to the local repo first如果这两个都正确定位,那么它应该首先检查本地存储库

Having to move my development environment offsite in response to COVID-19, my environment had not been established to directly connect to various public repositories since we were mirroring those repos in our server at the office.为了响应 COVID-19,我不得不将我的开发环境移到异地,因为我们在办公室的服务器中镜像这些存储库,因此我的环境尚未建立以直接连接到各种公共存储库。 However, my Maven was still contacting public repositories for our in-house releases.但是,我的 Maven 仍在联系我们内部版本的公共存储库。 This was odd, because I already had our in-house releases in my local repo.这很奇怪,因为我已经在我的本地仓库中发布了我们的内部版本。

The solution was to update the Maven configuration, in my settings.xml .解决方案是在我的settings.xml更新 Maven 配置。 Define profiles, a profile for the office and a profile for offsite.定义配置文件、办公室配置文件和非现场配置文件。 In the offsite profile, in addition to the public repos we were already mirroring at the office, I also defined a repository that matched the name, id, and URL of our server at the office where we stored our in-house releases - identically.在异地配置文件中,除了我们已经在办公室镜像的公共存储库之外,我还定义了一个存储库,该存储库与我们存储内部版本的办公室服务器的名称、ID 和 URL 相匹配 - 相同。 This allowed Maven to see that the library it was looking for did in-fact come from that repository and didn't need to go looking for it because it was already in the local repo.这允许 Maven 看到它正在寻找的库实际上来自该存储库并且不需要去寻找它,因为它已经在本地存储库中。 It also didn't matter that Maven wasn't going to be able to connect to the office server, it just needed to be defined. Maven 无法连接到办公室服务器也无关紧要,它只需要定义即可。

Before:前:

Downloading from central: https://repo.maven.apache.org/maven2/com/mycompany/test-core/1.1.0/test-core-1.1.0.pom
Downloading from jboss-releases: https://repository.jboss.org/nexus/content/repositories/releases/com/mycompany/test-core/1.1.0/test-core-1.1.0.jar
Downloading from repository-apache-org: https://repository.apache.org/content/groups/public/com/mycompany/test-core/1.1.0/test-core-1.1.0.pom
[WARNING] The POM for com.mycompany:test-core:jar:1.1.0 is missing, no dependency information available

This was a library we had produced and released ourselves, definitely not at Maven Central.这是我们自己制作和发布的库,绝对不是在 Maven Central。 Maven was just hunting around for it - lost with no direction. Maven 只是四处寻找它 - 迷失了方向。

I defined a new repo in the offsite profile, a repo that my environment definitely would not be able to connect to due to existing company firewall rules:我在异地配置文件中定义了一个新的存储库,由于现有的公司防火墙规则,我的环境肯定无法连接到该存储库:

    <repository>
      <id>leroy-releases</id>
      <name>Development Release Repository</name>
      <url>http://leroyhost:8080/repository/maven-releases/</url>
      <layout>default</layout>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>interval:15</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>

Please note, the profile section includes its own repositories section in which the repository section above must be defined in. You also need to activate the offsite profile:请注意, profile部分包含其自己的repositories repository部分,必须在其中定义上述repository部分。您还需要激活offsite配置文件:

<activeProfiles>
  <!--activeProfile>main-developer-profile</activeProfile-->
  <activeProfile>offsite-snapshots</activeProfile>
</activeProfiles>

I named the profile snapshots because without access to our office repository, no one is doing any releases out "in the field".我将配置文件命名为快照,因为如果无法访问我们的办公室存储库,就没有人在“现场”进行任何发布。

After:后:

Maven no longer searched the public repos for our in-house release artifacts. Maven 不再在公共存储库中搜索我们的内部发布工件。 It consulted my local repo and found all of our releases there.它查阅了我的本地仓库,并在那里找到了我们所有的版本。

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

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