How do I prevent Maven 2 from searching remote repositories for specific local depedencies?

后端 未结 4 891
一整个雨季
一整个雨季 2020-12-19 01:46

How do I prevent Maven 2 from searching remote repositories for specific dependencies that are in the local repository only?

相关标签:
4条回答
  • 2020-12-19 02:11

    Use fixed version numbers in your POM for your remote dependencies or the local versions you want to fetch from the local repository.

    Maven tries to be friendly and fetch the latest and greatest of whatever which has no version number specified.

    For a quick fix to not be waiting for the internet to be downloaded each time you build you can use mvn -o to force an offline build, and then it will not lose time trying to fetch new versions.

    The answer of @crowne is also very good advice, especially setting up your own nexus and making sure all remote repos are configured there so you will never have unpleasant surprises when a repo dissappears some day.

    0 讨论(0)
  • 2020-12-19 02:25
    1. set up nexus as a repository manager.
    2. add addtional remote proxied repositories if necessary
    3. add your local hosted repository (hosted on the nexus server)
    4. define a group of repositories in the correct search sequence with your local repo's first.
    5. change your builds to point at the nexus group url (use mirrorOf=* in your settings.xml)
    6. run your build and let nexus manage the local vs remote dependency resolution
    0 讨论(0)
  • 2020-12-19 02:29

    How do I prevent Maven 2 from searching remote repositories for specific depedencies that are in the local repository only

    Well, actually, Maven won't unless:

    • they are SNAPSHOT dependencies in which case this is the expected behavior.
    • they are missing a .pom file in which case you can provide it or generate it (see questions below).

    Related questions

    • How do I stop Maven 2.x from trying to retrieve non-existent pom.xml files for dependencies every build?
    • Maven install-file won’t generate pom.xml
    0 讨论(0)
  • 2020-12-19 02:32

    To prevent Maven from checking remote repositories at all, you can use the -o flag. Otherwise, Maven will check that any snapshot dependencies are up-to-date. You can use a dependency manager such as Nexus to get fine-grained control over dependency resolution. The repository section in your pom.xml or settings.xml file also has an updatePolicy element that allows you to configure how often Maven will check for updated dependencies.

    0 讨论(0)
提交回复
热议问题