Search code examples
gitmavenpom.xmlmaven-scm

How can I do a git pull in Maven?


I'm new to both maven and git and wanted to get some help in setting a project.

Is there a way to define a goal in the pom to push/pull from git during linked to a maven phase? For example, can I pull from git during the maven install phase?

If yes, how can that be accomplished? I would appreciate any code examples.


Solution

  • Good idea or not, here's how you could do a checkout (pull clone from Github) using Maven. Have your pom.xml look like this:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>br.com.javamagazine</groupId>
    <artifactId>engesoft</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>engesoft Maven Webapp</name>
    <url>http://maven.apache.org</url>
    
    <scm>
        <connection>scm:git:git://github.com/vitorsouza/EngeSoft.git</connection>
        <developerConnection>scm:git:https://[email protected]/vitorsouza/EngeSoft.git</developerConnection>
        <url>https://github.com/vitorsouza/EngeSoft</url>
    </scm>
    </project>
    

    Then use mvn scm:checkout. When I ran this, it pulled the code to folder target/engesoft. There's probably a way to configure it to place it somewhere else. Check out the following pages: