简体   繁体   中英

Maven ignores local repository

I'm trying to use jackson at a json project. And Maven is ignoring my local repository (where I have the library already set, from a previous project) and downloading from codehaus repo.

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?

Thanks in advance

Please set the Local Repository Path in eclipse that maps to your local repo path..

Go to Windows->Preferences->Maven->User Settings and change the settings.xml and your local repository path..

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. However, my Maven was still contacting public repositories for our in-house releases. 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 . 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. 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. 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.

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 was just hunting around for it - lost with no direction.

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:

<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. It consulted my local repo and found all of our releases there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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