Reputation: 13238
I've a maven project and I'm using the maven-release-plugin to prepare the release.
When I run the mvn --batch-mode release:prepare
command, it creates two commits as follows
(HEAD -> develop) [maven-release-plugin] prepare for next development iteration
(tag: myapp-1.0.0) [maven-release-plugin] prepare release myapp-1.0.0
This correctly updates all the pom files.
but I've some text files in my project where there is a version token. I'm looking for a way to replace these version tokens appropriately as per the commits.
For example, the prepare release
commit should replace the token to 1.0.0
and prepare for next development
should replace the token to 1.0.1-SNAPSHOT
I've checked the documentation but didn't find any way to do this. If somebody has any ideas on how to achieve this through maven-release-plugin or with the help of any other plugin, please suggest.
EDIT:
This issue is not solved even if I place the files inside resources directory. The thing I've observed is that the release plugin only selectively adds the pom.xml
files in the commit, not other files even if they are modified gets added into to the commits pushed by release plugin.
Let me clarify I am not looking for replacing version in the source file and have it replaced in the generated artifact. We can argue about why there is version field in non source file, but there are genuine scenarios anyone can think of.
As a developer I want that the release commit made by the maven release should be accurate i.e. It should contain all the changes associated with that specific release version.
Upvotes: 3
Views: 1621
Reputation: 4614
I am able to update version in non-pom files using maven release plugin.
maven-release-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<preparationGoals>resources:copy-resources@update-project-version scm:add -Dincludes=${target.file}</preparationGoals>
<checkModificationExcludes>${target.file}</checkModificationExcludes><!-- I dont want to update snapshot version in target file so I have excluded that from "prepare for next development iteration" -->
</configuration>
</plugin>
maven-resources-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
<executions>
<execution>
<id>update-project-version</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>${target.file}</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 1
Reputation: 35795
As khmarbaise said: Use ${project.version}
in the respective files, put them into a resources directory and use filtering.
Upvotes: 1