Update README versions for maven release

I support the opensource project on github containing a file README.mdwith installation instructions containing the current version of the project 1.0.0-SNAPSHOT.

When releasing a new version for the maven center, it is possible to automatically update this version number contained in README.md?

Releases are performed using maven-release-plugin, the versions in pom.xml are well updated, but I can not find anything in the documents to properly update this external file.

Example:

README.mdcurrently in 1.0.0-SNAPSHOT. It is outside of maven's sources / resources, but it is managed on git. on mvn release:prepareit must be updated to 1.0.0, and then maven should fix / change push to mark the new version. Then mvn release:performit should go to the next version of development 1.0.1-SNAPSHOT.

( Link to the project )

+4
source share
2 answers

You can use the maven-resources-plugin to do this, as pointed out in the comments.

I have not tried, but the configuration should look something like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.1</version>
  <executions>
    <execution>
      <id>readme-md</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.basedir}</outputDirectory>
        <resources>                                        
          <resource>
            <directory>${project.basedir}</directory>
            <includes>
              <include>README.md</include>
            </includes>
            <filtering>true</filtering>
          </resource>
        </resources>
        <encoding>UTF-8</encoding>
      </configuration>            
    </execution>
  </executions>
</plugin>

And on your README.md, where you want the version, you put a placeholder ${project.version}.

, copy-resources .

${project.basedir}, maven , , , README.md.

, , , , pom.xml . .

, , . , mvn resources:resources mvn release:perform. , .

+2

bash script, , README.md. - :

#!/bin/sh
VERSION=$1
mvn clean package
#modify the string manipulation command accordingly
sed -e "s/{VERSION}/${VERSION}/" ./README.md-tpl > ./README.md 

script . README.md-tpl .

0

Source: https://habr.com/ru/post/1623054/


All Articles