【问题标题】:How do I specify the commit message in the pom when using scm-maven-plugin?使用 scm-maven-plugin 时如何在 pom 中指定提交消息?
【发布时间】:2013-01-18 14:55:44
【问题描述】:

我正在尝试使用 maven SCM plugin 在自动构建期间将一些文件提交到 git repo,插件需要将提交消息设置为系统属性,我不想通过这在命令行上(我也在使用发布插件,这会导致问题)。

我已经尝试了通过 pom 添加消息系统属性的所有方法,但没有成功,这是我的 pom 的精简版:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.monkeys.coding</groupId>
    <artifactId>project</artifactId>
    <packaging>js</packaging>
    <version>1.0.4-SNAPSHOT</version>

    <name>Some Project</name>
    <description>Some Project where I want to add files to git during build</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <projectVersion>${project.version}</projectVersion>
    </properties>

    <scm>
        <connection>scm:git:http://some.git.repo:9080/git/module.git</connection>
        <developerConnection>scm:git:http://some.git.repo:9080/git/module.git</developerConnection>
        <url>http://some.git.repo:9080/git/module.git</url>
    </scm>

    <build>
        <finalName>${project.artifactId}</finalName>
        <!-- Package as js -->
        <extensions>
            <extension>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javascript-maven-plugin</artifactId>
                <version>2.0.0-alpha-1</version>
            </extension>
        </extensions>
    ...
    </build>

    <profiles>
        <!-- run this profile when releasing the library -->
        <profile>
            <id>release</id>
            <properties>
                <message>Add version files to git</message>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-scm-plugin</artifactId>
                        <version>1.8.1</version>
                        <configuration>
                            <message>Add version files to git</message>
                            <systemProperties>
                                <systemProperty>
                                    <name>message</name>
                                    <value>[Add Version to git]</value>
                                </systemProperty>
                            </systemProperties>
                        </configuration>
                        <executions>
                            <execution>
                                <id>add-version-to-git</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>add</goal>
                                    <goal>checkin</goal>
                                </goals>
                                <configuration>
                                    <basedir>./</basedir>
                                    <includes>versions/*</includes>
                                    <systemProperties>
                                        <systemProperty>
                                            <name>message</name>
                                            <value>[Add Version to git]</value>
                                        </systemProperty>
                                    </systemProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

通过配置文件属性添加消息似乎有效,文件已提交获取并且消息出现在存储库中,但构建失败并出现此错误:

    [ERROR] Provider message:
    [ERROR] The git-commit command failed.
    [ERROR] Command output:
    [ERROR] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 28.637s
    [INFO] Finished at: Fri Jan 18 12:59:40 GMT 2013
    [INFO] Final Memory: 19M/81M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-scm-plugin:1.8.1:checkin (add-version-to-git) on project: Command failed.The git-commit command failed. -> [Help 1]

关于我做错了什么有什么想法吗?

干杯 抢

【问题讨论】:

    标签: git maven-3 commit system-properties maven-scm


    【解决方案1】:

    尝试将pom.xml 更改为如下所示:

    ...
        <executions>
            <execution>
                <id>add-version-to-git</id>
                <phase>package</phase>
                <goals>
                    <goal>add</goal>
                    <goal>checkin</goal>
                </goals>
                <configuration>
                    <basedir>./</basedir>
                    <includes>versions/*</includes>
                    <message>[Add Version to git]</message>
                </configuration>
            </execution>
        </executions>
    ...
    

    尝试使用message 属性而不是systemProperties

    或者您可以随时在命令行中执行此操作,例如:

    mvn -Dmessage="<commit_log_here>" scm:checkin
    

    如上所述here

    【讨论】:

    • 谢谢我使用了最重要的建议,运行我们 CI 服务器的人往往会弄乱我们设置的 mvn 命令,所以我不想在命令行中添加它:)
    猜你喜欢
    • 1970-01-01
    • 2015-02-14
    • 2022-07-04
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2016-09-17
    相关资源
    最近更新 更多