使用maven 自动为 js/css加版本号

来源:互联网 发布:怎么在淘宝投诉卖家 编辑:程序博客网 时间:2024/04/30 13:10

原理就是使用 maven-replacer-plugin 替换html 中的 js、css 等,难点主要是maven-war-plugin的生命周期的问题,参考配置如下:

   <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-war-plugin</artifactId>                <version>2.3</version>                <configuration>                    <useCache>true</useCache>                    <outputDirectory>${basedir}/../target</outputDirectory>                </configuration>                <executions>                    <execution>                        <id>prepare-war</id>                        <phase>prepare-package</phase>                        <goals>                            <goal>exploded</goal>                        </goals>                    </execution>                </executions>            </plugin>           <plugin>                <groupId>com.google.code.maven-replacer-plugin</groupId>                <artifactId>replacer</artifactId>                <version>1.5.3</version>                <executions>                    <execution>                        <phase>prepare-package</phase>                        <goals>                            <goal>replace</goal>                        </goals>                    </execution>                </executions>                <configuration>                    <includes>                        <include>${basedir}/target/message-center-product/**/*.html</include>                  <!--      <include>target/message-center-product/**/*.js</include>-->                    </includes>                    <replacements>                        <replacement>                            <token>\.css\"</token>                            <value>.css?v=${maven.build.timestamp}\"</value>                        </replacement>                        <replacement>                            <token>\.css\'</token>                            <value>.css?v=${maven.build.timestamp}\'</value>                        </replacement>                        <replacement>                            <token>\.js\"</token>                            <value>.js?v=${maven.build.timestamp}\"</value>                        </replacement>                        <replacement>                            <token>\.js\'</token>                            <value>.js?v=${maven.build.timestamp}\'</value>                        </replacement>                    </replacements>                </configuration>            </plugin>


原创粉丝点击