How can I do a git pull in Maven?

亡梦爱人 提交于 2019-11-30 00:54:41

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://vitorsouza@github.com/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:

Instead of doing this during the Maven build, use a CI server like Jenkins. It will do the git pull before running maven, so the build tool can concentrate on it's main purpose: Building source code.

This also makes it more simple for you to develop since pull's will only happen when you want them. If you pull all the time, another developer can change something and you will get errors that you don't expect.

James Evans

The scm:checkout goal Vitor is referring to is a clone, not a pull (huge difference in Git).

I had to use the exec goal to do what you're describing. I also didn't want to do an entire clone each time there was a build. Instead, I use git reset --hard and then pull -f origin Release:Release (via exec).

If I find a better way (and there HAS to be one) I'll post it here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!