首页 > 解决方案 > Maven release not calling resources:resources plugin

问题描述

I'm trying to deploy a maven project and upgrade the versions by executing the maven release plugin on TeamCity. I am able to successfully do this - however, the resources:resources plugin is no longer executed. Or more accurately, it is executed but not doing the expected changes. When I run a maven package or install however, it works. Not sure what it is I'm missing. Any help would be appreciated.

Below is my code Parent pom

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <delimiters>
                        <delimiter>@</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <releaseProfiles>releases</releaseProfiles>
                    <localCheckout>true</localCheckout>
                    <arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%</arguments>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare</id>
                        <goals>
                            <goal>prepare</goal>
                        </goals>
                        <configuration>
                            <pushChanges>false</pushChanges>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Child pom

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <delimiters>
                    <delimiter>@</delimiter>
                </delimiters>
                <useDefaultDelimiters>false</useDefaultDelimiters>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <!-- Adds ${buildNumber} to buildNumber.properties -->
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>application_local.properties</exclude>
            </excludes>
        </resource>
    </resources>
</build>

I run the following command:

mvn -B -e initialize release:branch release:clean release:prepare release:stage -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%...

And I have in my child project in the src/main/resources folder a file called application-deployed.properties with the following lines which is what I want to change.

# build information by team city
child.propject.buildNumber=@CONTINUOUS_BUILD_ID@
child.propject.buildVersion=@GIT_COMMIT@
child.propject.buildBranch=@GIT_BRANCH@

Any help is much appreciated

标签: javamaventeamcitymaven-release-pluginmaven-resources-plugin

解决方案


maven-resources-plugin无权访问您在命令行中传递的参数。这样做的原因是在单独的 Maven 执行中调用了deploy目标(其中包括resources:resources等) 。maven-release-plugin

为了克服这个限制,maven-release-plugin接受arguments参数的目标可用于将参数传递给上述单独的 Maven 执行。尝试通过以下方式修改命令行:

mvn -B -e initialize release:branch release:clean release:prepare release:stage -Darguments="-DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%"


推荐阅读