如何使用properties-maven-plugin:write-project-properties仅编写指定的属性

时间:2016-06-02 10:52:07

标签: maven

我正在尝试使用properties-maven-plugin将Git属性写入指定的文件。为此,我使用以下代码:

<plugin>
    <groupId>ru.concerteza.buildnumber</groupId>
    <artifactId>maven-jgit-buildnumber-plugin</artifactId>
    <version>1.2.7</version>
    <executions>
        <execution>
            <id>git-buildnumber</id>
            <goals>
                <goal>extract-buildnumber</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
</plugin>
<!--write project properties to file -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>write-project-properties</goal>
            </goals>
            <configuration>
                <outputFile>${project.basedir}/../build-info.tmp</outputFile>
                <properties>
                    <property>
                        <name>revision</name>
                        <value>${revision}</value>
                    </property>
                    <property>
                        <name>buildnumber</name>
                        <value>${buildnumber}</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

现在我的问题是:

  1. 它提供分支,内部版本号,commitscount,标记,分支等,但我想从maven-jgit-buildnumber-plugin使用属性插件中仅提取修订版本和内部版本号。
  2. 我也想重命名它们。例如git.buildnumberbuildnumbergit.revisionrevision
  3. 我是否可以通过手动从用户的命令提示符中取出buildnumber
  4. 有人可以通过这个建议我吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

这是有效....通过将其保存在配置文件中并给出命令clean install -P profilename -Dversion = 16

    <plugin>
                <groupId>com.keyboardsamurais.maven</groupId>
                <artifactId>maven-timestamp-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <propertyName>date</propertyName>
                    <timestampPattern>EEE MMM dd hh:mm:ss yyyy Z</timestampPattern>
                    <timeZone>IST</timeZone>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>ru.concerteza.buildnumber</groupId>
                <artifactId>maven-jgit-buildnumber-plugin</artifactId>
                <version>1.2.7</version>
                <executions>
                    <execution>
                        <id>git-buildnumber</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>extract-buildnumber</goal>
                        </goals>
                        <configuration>
                            <revisionProperty>revision</revisionProperty>
                            <buildnumberProperty>version</buildnumberProperty>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>set-system-properties</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <property>
                                    <name>revision</name>
                                    <value>${revision}</value>
                                </property>
                                <property>
                                    <name>date</name>
                                    <value>${date}</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.internetitem</groupId>
                <artifactId>write-properties-file-maven-plugin</artifactId>
                <version>1.0.1</version>
                <executions>
                    <execution>
                        <id>write-properties-file</id>
                        <phase>install</phase>
                        <goals>
                            <goal>write-properties-file</goal>
                        </goals>
                        <configuration>
                            <filename>build-info.tmp</filename>
                            <outputDirectory>${project.basedir}/../</outputDirectory>
                            <properties>
                                <property>
                                    <name>revision</name>
                                    <value>${revision}</value>
                                </property>
                                <property>
                                    <name>date</name>
                                    <value>${date}</value>
                                </property>
                                <property>
                                    <name>version</name>
                                    <value>${version}</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>