maven install and deploy 3rd party dependencies with simple command line

后端 未结 3 645
长情又很酷
长情又很酷 2021-02-09 14:29

We have a number of third party dependencies that aren\'t hosted anywhere. For each of these we have a jar file that we\'d like to be able to install and/or deploy to our reposi

3条回答
  •  无人共我
    2021-02-09 14:52

    Ok, I found a solution that allows me to run just mvn install or mvn deploy and have the jar file installed to the local or remote repository. Inspired by a post to the maven-users list and using the build-helper plugin, in the parent pom, I have:

    
        
            
            
                org.codehaus.mojo
                build-helper-maven-plugin
                1.5
                
                    
                        attach-artifacts
                        package
                        
                            attach-artifact
                        
                        
                            
                                
                                    ${artifactId}-${version}.jar
                                    jar
                                
                            
                        
                    
                
            
        
    
    

    And then in the child poms, I have:

    pom
    ...
    ...
    ...
    ...
    
        
            
                org.codehaus.mojo
                build-helper-maven-plugin
            
        
    
    

    Some of the pieces of this that initially tripped me up:

    • The attach-artifact execution should be under so it doesn't get executed if you mvn install or mvn deploy the parent pom.
    • The children need to specify the build-helper-maven-plugin under the build plugins so that code from the parent gets run.
    • The children have to be declared as having pom because you can't add a jar to an artifact if it has the same name as the artifact.

    The only downside I see to this approach is that the artifact gets deployed as type pom instead of type jar. But I haven't seen any real consequences of that.

提交回复
热议问题