1

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

sometimes24
  • 355
  • 4
  • 15

2 Answers2

1

maven-resources-plugin doesn't have access to the parameters you pass in the command line. Reason for this is that deploy goal (which includes resources:resources, among others) is invoked by maven-release-plugin in a separate Maven execution.

In order to overcome this limitation, goals of maven-release-plugin accept arguments parameter that could be used to pass parameters to aforementioned separate Maven executions. Try to modify your command line the following way:

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%"

Aleksei Budiak
  • 871
  • 5
  • 16
  • Unfortunately this didn't work - I tried double and single quotes. It might be because I was executing the command from TeamCity – sometimes24 Oct 17 '18 at 13:28
  • 1
    @sometimes24, I didn't notice that your maven-release-plugin already has `` tag in the config. In this case the plugin ignores arguments passed via command line and uses the contents of the tag instead. – Aleksei Budiak Oct 18 '18 at 11:30
0

I was able to solve the issue by adding the following to the maven release plugin in the parent pom

<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=${CONTINUOUS_BUILD_ID} -DGIT_COMMIT=${GIT_COMMIT} -DGIT_BRANCH=${GIT_BRANCH}</arguments>

and then calling my initial 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%...
sometimes24
  • 355
  • 4
  • 15