Maven:如何在POM文件中引用开发人员的电子邮件?

时间:2015-03-06 11:53:47

标签: maven pom.xml

众所周知,如果我在POM文件中有这样的属性:

<project ...>
    ...
    <groupId>com.bosch</groupId>
    <artifactId>jenkins-ci</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>
    ...
    <organization>
        <name>Organization Name</name>
    </organization>
    ...
</project>

...我可以使用${project.artifactId}${project.organization.name}等来引用它们。

但是如何在下面的标签中引用开发人员的ID或电子邮件?

<project ...>
    ...
    <developers>
        <developer>
            <id>dev1</id>
            <name>Developer 1</name>
            <email>developer1@email.com</email>
        </developer>
        <developer>
            <id>dev2</id>
            <name>Developer 2</name>
            <email>developer2@email.com</email>
        </developer>
    </developers>
    ...
</project>

编辑:来自 @ P-aBäckström的答案似乎是正确答案,但对我而言,只有在我使用help:evaluate时才有效。

采用以下示例:

<project
    ...
    <properties>
        <testId>${project.developers[0].id}</testId>
    </properties>
    ...
    <developers>
        <developer>
            <id>dev1</id>
            <name>Developer 1</name>
            <email>developer1@email.com</email>
        </developer>
        <developer>
            <id>dev2</id>
            <name>Developer 2</name>
            <email>developer2@email.com</email>
        </developer>
    </developers>
    ...
    <organization>
        <name>${project.developers[0].id}</name>
    </organization>
    ...
</project>

然后以下工作......

C:\workspaces\rafael_workspace\jenkins-parent-pom>mvn help:evaluate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Jenkins POM 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.1.1:evaluate (default-cli) @ jenkins-ci ---
[INFO] No artifact parameter specified, using 'com.test:jenkins-ci:pom:0.0.1' as project.
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${project.developers[0].id}
[INFO]
dev1
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${testId}
[INFO]
dev1
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${project.organization.name}
[INFO]
dev1

但是,当我使用C:\workspaces\rafael_workspace\jenkins-parent-pom>mvn help:effective-pom来解析有效POM时,这些引用不会改变。有效的POM仍向我显示${project.developers[0].id}而不是实际值dev1

1 个答案:

答案 0 :(得分:5)

您可能需要升级Maven,但这应该可行:

${project.developers[0].id}