Maven: keeping dependent jars in project version control

后端 未结 5 1926
猫巷女王i
猫巷女王i 2021-01-02 01:37

So, I have a war project with several dependent jars that are not available in any repository. Up until recently, I\'d been keeping them in src/main/webapp/WEB-INF/lib

5条回答
  •  暖寄归人
    2021-01-02 01:44

    At my company we are using Archiva, it is by far the simplest Repository Manager to set up and maintain. Especially if you go with the stand-alone based version. The each developer just sets up a profile in their ~/.m2/settings.xml file to point to the internal repository. If this is too much trouble, just put the internal repository in the in the pom.xml directly, but that is really bad practice. If the repository url ever moves, you have to update all your projects pom.xml files. Where as using settings.xml puts that burden on the developer to update their local configuration.

    
    
        
            
                internal
                
                    true
                
                
                    
                        mycompany.internal
                        Internal Release Repository
                        http://maven.mycompany.com/repository/internal/
                        
                            true
                        
                        
                            false
                        
                    
                    
                        mycompany.snapshots
                        Internal Snapshot Repository
                        http://maven.mycompany.com/repository/snapshots/
                        
                            false
                        
                        
                            true
                        
                    
                
            
        
    
    
        
            
                internal
                guest
            
            
                snapshots
                guest
            
        
    
    
    

    If setting up a Repository Manager is too much trouble, I think you need to reconsider the alternative of manually adding stuff to your local repository by hand, which is very error prone and time consuming. I run an Archiva instance for my personal development just because it is so easy to add the release plug in and manage versions without having to remember all the arcane -D options required to add stuff to your local repository on every machine. Copying the ~/.m2/settings.xml file is super easy and if it works on one machine it works on all of them.

    Here is what you add to your pom.xml to enable automatically doing releases and pushing artifacts to a repository, in my case it is Archiva.

    
       
           internal
           Internal Archiva Repository
           http://maven.mycompany.com/repository/internal/
           default
           false
       
       
           snapshots
           Internal Archiva Repository
           http://maven.mycompany.com/repository/snapshots/
           default
           false
       
    
    

    Then all you do is mvn clean release:prepare to automatically update your pom.xml version check in, tag and optionally branch the release and package all the artifacts, and then mvn release:perform to push the artifacts to the remote repository and check in the newly versioned pom.xml and you are ready for the next version to start development.

    Snapshots got to snaphots and Releases go to internal automatically with the release plug in. You do have to configure the scm plug in as well, but that is just a few lines of configuration that you only have to touch once as well.

    This is what it looks like for git, we are using Gitorious as our git Repository Manager

    
        scm:git:git://gitorious.mycompany.com:myproject/myproject.git
        scm:git:ssh://git@gitorious.mycompany.com/myproject/myproject.git
        http://gitorious.mycompany.com/myproject/myproject
    
    

    An old desktop computer running Linux can handle repository duties like this for a development team without having to involve procurement and IT.

提交回复
热议问题