Closed Riduidel closed 9 months ago
Currently looking for search and replace / file modifications maven plugins. I'm checking resources such as
And here : https://maven.apache.org/plugins/index.html
https://ant.apache.org/manual/Tasks/replace.html
https://mvnrepository.com/artifact/com.google.code.maven-replacer-plugin/maven-replacer-plugin/1.4.1 -> too old according to the guy from the previous github repo link
https://floverfelt.org/find-and-replace-maven-plugin/examples/basic.html Questions :
The following is a configuration to recursively process only file contents for files ending in .yml in the target directory.
<plugin>
<groupId>io.github.floverfelt</groupId>
<artifactId>find-and-replace-maven-plugin</artifactId>
<executions>
<execution>
<id>exec</id>
<phase>package</phase>
<goals>
<goal>find-and-replace</goal>
</goals>
<configuration>
<replacementType>file-contents</replacementType>
<baseDir>target/</baseDir>
<findRegex>_</findRegex>
<replaceValue>-</replaceValue>
<recursive>true</recursive>
<fileMask>.yml</fileMask>
</configuration>
</execution>
</executions>
</plugin>
- Does the plugin need to modify just a line in the README or a variable containing the version to change ?
Since the readme is a markdown file, which has no interpolation mechanism, we will have to directly change the line
- Does it need to remove the .yml or can i just do it myself
You'll have to remove the yml file by youself
- Does it need to be in a particular place in the pom.xml file or can i just put it at the end of after the last actual plugin ?
Have you ever heard about maven profiles ? Since your coe will have to be run only during maven release process, there is a way to trigger that by putting your code in a profile, and having that profile activated on release (see poml.xml
)
See as as an example this profile
<profile>
<id>update_version_in_files</id>
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>echo-maven-plugin-1</id>
<phase>prepare-package</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message><![CDATA[Pour Gaëtan]]></message>
<level>INFO</level>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Command to use to test your code is mvn package --projects :system --activate-profiles settings-aadarchi,update_version_in_files
Then validate the README.md
now contains the new version
Create profile not called by default which gonna take the right version number thanks to : '=[0-9]+.[0-9]+.[0-9]+ '
The project version on the on_release_perform_maven_release.yml file is set to default, so i have a doubt about replacing the version number from the readme by this one. (so I think I just forgotten where i have to take it. Not in the on_release_update_readme.yml I assume, since I'me supposed to delete it) But so far I've been able to modify the readme file with the find-and-replace-maven-plugin
Task finished, but only one issue remains : if the command is run multiple times, the SNAPSHOT is added multiple times too at the end of the version
Won't fix (we prefer to use the github action for that, as it generates a PR)
Using a github action for that is in fact suboptimal, so remove the
.github/workflows/on_release_update_readme.yml
action and replace it with the correct set of maven plugins