Maven - deploy dependencies to remote repository

前端 未结 3 1842
小蘑菇
小蘑菇 2020-12-28 09:46

I have a few projects with LOTS of maven dependencies. When I invoke the command mvn deploy (or some variation of it), I would like to not only have the project itself depl

3条回答
  •  情话喂你
    2020-12-28 10:40

    Here's how it works in a nutshell, assuming your remote repository (Nexus, or Artifactory, or the like) and settings.xml are configured correctly.

    Let's say you have a project with one dependency on commons-logging. When Maven resolves your project's dependencies as part of a build, it does these steps:

    1. Checks local repo for commons-logging.
    2. If found, done. Continue with build.
    3. If not found: checks for commons-logging in the remote repo.
    4. If found, download artifact to local repo. Done; continue with build.
    5. If not found in remote repo: remote repo contacts central to download commons-logging. Then it's available for Maven to download to local repo. Done; continue with build.

    At the end of these steps, commons-logging should be in both your local and remote repos with nothing further to do. If this is not the case, then either your settings.xml is not configured to connect to the remote repo when searching for dependencies (is it contacting central directly?) or Nexus isn't configured correctly.

    ---- Edit ----

    Here's a snippet of my settings.xml that works. @Raghuram gave you a good tip when he suggested you enable both profiles; if you somehow enabled only the public-snapshots profile your builds would continue to hit maven central directly.

    ....
    
        
        
            maven2
            *
            http://repository.someCompany.com/maven2RepoOrGroupInNexus
        
    
    ....
    
        
            repo-profile
            
                
                    central
                    http://gotoNexus  
                    
                        true
                        daily
                    
                    
                        true
                        daily
                    
                
            
        
    
    
        repo-profile  
    
    

    Note the activeProfiles element at the bottom; that's how to ensure you'll use Nexus instead of Maven central with every mvn command.

    You still need to make sure Nexus is configured so that the URL defined in the includes content from Maven central, but how to configure Nexus would be a separate question.

    Reference: Nexus docs for Maven configuration

提交回复
热议问题