如何使用ssh-agent的maven进行git克隆?

时间:2015-10-14 10:10:15

标签: git maven

我想使用maven克隆存储库,并且身份验证必须使用现有的ssh-agent。

我当前的插件配置:

Template Points{Point(x1,y1),Point(x2,y2)....} 
Target Point1{Point(x11,y11),Point(x12,y12)....}
Target Point2{Point(x21,y21),Point(x22,y22)....}
Target Point3{Point(x31,y31),Point(x32,y32)....}

Calculate L2 distant.

d1 = sqrt((x1-x11)^2+(y1-y11)^2) + sqrt((x2-x12)^2+(y2-y12)^2) +...
d2 = sqrt((x1-x21)^2+(y1-y21)^2) + sqrt((x2-x22)^2+(y2-y22)^2) +...
d3 = sqrt((x1-x31)^2+(y1-y31)^2) + sqrt((x2-x32)^2+(y2-y32)^2) +...

Find the minimum d of three, and it's the best match!

身份验证失败:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.9.4</version>
    <configuration>
        <providerImplementations>
                <git>jgit</git>
        </providerImplementations>
    </configuration>
    <dependencies>
        <dependency>
                <groupId>org.apache.maven.scm</groupId>
                <artifactId>maven-scm-provider-jgit</artifactId>
                <version>1.9.4</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>clone-github-wiki</id>
            <goals>
                <goal>checkout</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <checkoutDirectory>${project.basedir}/target/github-wiki</checkoutDirectory>
                <connectionType>connection</connectionType>
                <connectionUrl>scm:git:git@github.com:xyz/abc.wiki.git</connectionUrl>
            </configuration>
        </execution>
    </executions>
</plugin>

1 个答案:

答案 0 :(得分:1)

exec插件可用于调用git命令。在这种情况下,使用ssh-agent。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <id>github-wiki-clone</id>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <executable>git</executable>
                <arguments>
                    <argument>clone</argument>
                    <argument>-b</argument>
                    <argument>master</argument>
                    <argument>git@github.com:abc/xyz.wiki.git</argument>
                    <argument>target/github-wiki</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>