[英]SVN revision number accessible in compiled GWT package
I have a GWT project which has its source managed in SVN, is packaged using Maven and has its builds managed via Hudson. 我有一个GWT项目,其源代码在SVN中管理,使用Maven打包,并通过Hudson管理其构建。 I want to get the SVN revision number of the latest check-in/build to be visible in a comment at the bottom of the application root HTML file.
我想在应用程序根HTML文件底部的注释中看到最新签入/构建的SVN修订版号。 I don't care where in the development process this happens!
我不关心在开发过程中发生这种情况!
Here are the options I've Googled for so far, with no success: 以下是我迄今为止用Google搜索的选项,但没有成功:
Does anyone have a complete, end-to-end example of how to get any of these working? 有没有人有一个完整的,端到端的例子来说明如何使这些工作? I keep finding little snippets of code/config which do one part of the job, but not anything that is exactly what I'm looking for.
我一直在寻找代码/配置的小片段,它们完成了工作的一部分,但并不是我正在寻找的任何东西。
Thanks! 谢谢!
You can achieve what you're looking for with a combination of Maven and Hudson. 通过组合Maven和Hudson,您可以实现您所需要的。 In this example let's imagine you want the file
version.txt
at the root of your web app to contain the revision. 在这个例子中,让我们假设您希望Web应用程序根目录下的文件
version.txt
包含修订版本。
version.txt
: version.txt
:
${SVN_REVISION}
In your project's pom.xml
enable filtering in the maven-war-plugin
: 在你的项目的
pom.xml
启用maven-war-plugin
中的过滤:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webResources>
<webResource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>version.txt</include>
</includes>
</webResource>
</webResources>
</configuration>
</plugin>
Make sure that Hudson is building your project via. 确保Hudson正在构建您的项目。 Subversion checkout and it will set the
SVN_REVISION
environment variable for every build and Maven will fill it in. Subversion checkout,它将为每个构建设置
SVN_REVISION
环境变量,Maven将填充它。
This solution is for those who keep getting {SVN_REVISION} instead of the actual SVN_REVISION value inside the target file . 此解决方案适用于那些持续获取{SVN_REVISION}而不是目标文件中的实际SVN_REVISION值的人 。
My solution was to also use filtering. 我的解决方案也是使用过滤。 However since I wanted the SVN_REVISION to appear inside my gwt app's main html page (as a means of "fighting" the user's cache, making sure that if we carry out a new build, then the user downloads the latest html file), I wasn't able to use Jason Terk's solution.
但是,因为我希望SVN_REVISION出现在我的gwt应用程序的主html页面内(作为“打击”用户缓存的一种方式,确保如果我们执行新的构建,然后用户下载最新的html文件),我不知道能够使用Jason Terk的解决方案。 The html file simply printed {SVN_REVISION} instead of the actual SVN_REVISION value.
html文件只打印{SVN_REVISION}而不是实际的SVN_REVISION值。
So I defined a property inside <properties>
: 所以我在
<properties>
定义了一个属性:
<properties>
...
<buildVersion>${SVN_REVISION}</buildVersion>
...
</properties>
I then made sure I was filtering the appropriate html file (like described in Jason's solution), and then "extracted" the SVN_REVISION in the html file like so: 然后我确定我正在过滤相应的html文件(如Jason的解决方案中所述),然后在html文件中“提取”SVN_REVISION,如下所示:
<script type="text/javascript">
...
var versionIdSuffix = '?v=${buildVersion}';
....
</script>
In a nutshell - I wasn't able to directly reference the {SVN_REVISION} property from inside the html file, so I "wrapped" it through <properties>
, letting maven reference it instead. 简而言之 - 我无法直接从html文件中引用{SVN_REVISION}属性,所以我通过
<properties>
“包装”它,让maven引用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.