/find-and-replace-maven-plugin

A maven plugin for replacing content in files, filenames and directories.

Primary LanguageJavaApache License 2.0Apache-2.0

Latest version Build Quality Gate Status Plugin docs

find-and-replace-maven-plugin

A maven plugin for replacing content in files, filenames and directories.

Usage

A short usage guide is available in the plugin docs.

Example: Replace underscores with hyphen

<plugin>
   <groupId>software.xdev</groupId>
   <artifactId>find-and-replace-maven-plugin</artifactId>
   <executions>
      <execution>
         <id>replace-underscore-with-hyphen</id>
         <phase>process-sources</phase>
         <goals>
            <goal>file-contents</goal>
         </goals>
         <configuration>
            <baseDir>testing/</baseDir>
            <fileMask>test.txt</fileMask>
            <findRegex>_</findRegex>
            <replaceValue>-</replaceValue>
         </configuration>
      </execution>
   </executions>
</plugin>
Replace contents of auto-generated files (OpenAPI generator)
<plugin>
   <groupId>software.xdev</groupId>
   <artifactId>find-and-replace-maven-plugin</artifactId>
   <executions>
      <execution>
         <!-- Remove so that we don't need additional dependency -->
         <id>remove-unused-import-com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider</id>
         <phase>process-sources</phase>
         <goals>
            <goal>file-contents</goal>
         </goals>
         <configuration>
            <baseDir>${generatedDirRelative}/software/xdev/${componentName}/client/</baseDir>
            <fileMask>ApiClient.java</fileMask>
            <!-- @formatter:off DO NOT INTRODUCE LINE BREAK -->
            <findRegex>^import com\.fasterxml\.jackson\.jaxrs\.json\.JacksonJsonProvider;(\r?\n)</findRegex>
            <!-- @formatter:on -->
            <replaceLineBased>false</replaceLineBased>
         </configuration>
      </execution>
      <execution>
         <!-- Changes with each generator version -->
         <id>remove-generated-annotation</id>
         <phase>process-sources</phase>
         <goals>
            <goal>file-contents</goal>
         </goals>
         <configuration>
            <baseDir>${generatedDirRelative}/software/xdev/${componentName}/</baseDir>
            <recursive>true</recursive>
            <fileMask>.java</fileMask>
            <findRegex>^@jakarta\.annotation\.Generated.*(\r?\n)</findRegex>
            <replaceAll>false</replaceAll>
            <replaceLineBased>false</replaceLineBased>
         </configuration>
      </execution>
      <execution>
         <!-- Requiring Java serialization indicates a serious misuse of the API -->
         <id>remove-serialVersionUID</id>
         <phase>process-sources</phase>
         <goals>
            <goal>file-contents</goal>
         </goals>
         <configuration>
            <baseDir>${generatedDirRelative}/software/xdev/${componentName}/</baseDir>
            <recursive>true</recursive>
            <fileMask>.java</fileMask>
            <findRegex>^.*serialVersionUID.*(\r?\n)(\s*\r?\n)?</findRegex>
            <replaceAll>false</replaceAll>
            <replaceLineBased>false</replaceLineBased>
         </configuration>
      </execution>
   </executions>
</plugin>

Installation

Installation guide for the latest release

Support

If you need support as soon as possible and you can't wait for any pull request, feel free to use our support.

Contributing

See the contributing guide for detailed instructions on how to get started with our project.

Dependencies and Licenses

View the license of the current project or the summary including all dependencies