Maven pom variables as command argument

 ̄綄美尐妖づ 提交于 2019-12-14 03:33:44

问题


I want to be able to do something like:

mvn release:branch -DbranchName=${project.version}

I'm sure this won't work and I'm asking for help on how to achieve it. mvn release:branch require a branchName. I need the branchName on the command line argument taking the project version as value. My pom looks like this:

<profile>
          <id>branch</id>
          <activation>
            <property>
              <name>branchName</name>
            </property>
          </activation>
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                  <tagNameFormat>v@{project.version}-beta</tagNameFormat>
                  <autoVersionSubmodules>true</autoVersionSubmodules>
                  <suppressCommitBeforeBranch>true</suppressCommitBeforeBranch>
                  <remoteTagging>false</remoteTagging>
                </configuration>
              </plugin>
            </plugins>
          </build>
      </profile>

This profile is triggerred only when branchName is present on the command line argument.

I appreciate your help.

Edit: updated pom

<profile>
          <id>branch</id>
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                  <branchName>@{project.version}</branchName>
                  <tagNameFormat>v@{project.version}-beta</tagNameFormat>
                  <autoVersionSubmodules>true</autoVersionSubmodules>
                  <suppressCommitBeforeBranch>true</suppressCommitBeforeBranch>
                  <remoteTagging>false</remoteTagging>
                </configuration>
              </plugin>
            </plugins>
          </build>
      </profile>

回答1:


The correct way to activate a profile is:

Remove the <activation> stanza and in your case do

mvn release:branch -P branch

This is all you should need given that you have hard coded ${project.version} in the configuration anyway.

There is no way to get ${project.version} without running the mvn command to begin with or parsing the pom.xml externally.

The documentation on this is pretty clear:

To create a branch execute this command:

mvn release:branch -DbranchName=my-branch

By default, the POM in the new branch keeps the same version as the local working copy, and the local POM is incremented to the next revision. If you want to update versions in the new branch and not in the working copy, run:

mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false


来源:https://stackoverflow.com/questions/24910586/maven-pom-variables-as-command-argument

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