maven-replacer-plugin

时间:2022-10-15 08:30:10

今天多认识了下这个maven插件。

基本用法:

 <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>(version)</version>
        <executions>
            <execution>
                <phase>prepare-package</phase>
                <goals>
                    <goal>replace</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <ignoreMissingFile>true</ignoreMissingFile>
            <file>target/someapp/jsp/helloWorld.jsp</file>
            <outputFile>
                target/someapp/jsp/helloWorld-updated.jsp
            </outputFile>
            <regex>false</regex>
            <token>$BUILD_NUMBER$</token>
            <value>${buildNumber}</value>
        </configuration>
    </plugin>

给一些静态链接增加版本号:

   <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <basedir>${project.build.directory}</basedir>
                    <filesToInclude>someapp/WEB-INF/**/*.jsp</filesToInclude>
                    <replacements>
                        <replacement>
                            <token>
                                <![CDATA[<\s*link\s+href="([^"]+)"[^>]*\s*>]]>
                            </token>
                            <value>
                                <![CDATA[<link rel="stylesheet" href="$1?v=${maven.build.timestamp}"/>]]>
                            </value>
                        </replacement>
                        <replacement>
                            <token>
                                <![CDATA[<\s*script\s+src="([^"]+)"[^/>]*\s*>]]>
                            </token>
                            <value>
                                <![CDATA[<script src="stylesheet" href="$1?v=${maven.build.timestamp}">]]>
                            </value>
                        </replacement>
                    </replacements>
                    <regexFlags>
                        <regexFlag>CASE_INSENSITIVE</regexFlag>
                        <regexFlag>DOTALL</regexFlag>
                    </regexFlags>
                </configuration>
            </plugin>