Maven之使用SVN版本号

1.有时候我们在项目中需要给js,css加版本参数来避免浏览器缓存,比如

<script type="text/javascript" src="/js/jquery-1.8.2.min.js?v=${v?if_exists}"></script>

 这个时候,我们可以使用项目的svn版本号来作为参数(时间戳也是一种选择)。那么我们如何使用maven在打包时自动获取svn版本号呢?可以使用maven-svn-revision-number-plugin来解决这个问题。

2.在pom.xml中加入如下内容:

<plugin>
    <groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
    <artifactId>maven-svn-revision-number-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <verbose>true</verbose>
        <entries>
            <entry>
                <prefix>prefix</prefix>
                <depth>empty</depth>
            </entry>
        </entries>
    </configuration>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>revision</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.tmatesoft.svnkit</groupId>
            <artifactId>svnkit</artifactId>
            <version>1.7.8</version>
        </dependency>
    </dependencies>
</plugin>
<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

 3.在项目的src/main/resources目录下有web.properties文件

js.css.v=${prefix.revision}

 4.当使用maven打包项目或者在插件中运行时,${prefix.revision}会被svn版本号代替



 

猜你喜欢

转载自lanhuidong.iteye.com/blog/1975808