简体   繁体   English

SVN修订版号可在编译的GWT包中访问

[英]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搜索的选项,但没有成功:

  • Can I get Hudson to, after building, write the build/revision number to one of its build output files (namely the application root HTML file)? 在构建之后,我可以让Hudson将构建/修订号写入其构建输出文件之一(即应用程序根HTML文件)吗? I've seen no way to do this. 我见过没办法做到这一点。
  • Can I get Maven to write the SVN revision number to one of its build output files (namely the application root HTML file)? 我可以让Maven将SVN修订号写入其构建输出文件之一(即应用程序根HTML文件)吗? I've seen ways of Maven writing this to a JAR/WAR manifest file (which can then be accessed in the Java code), but I'm not sure that this works in GWT (I'm not particularly knowledgeable about the internals of GWT). 我已经看到Maven将这个写入JAR / WAR清单文件(可以在Java代码中访问)的方法,但我不确定这是否适用于GWT(我不是特别了解内部的GWT)。
  • Can I get SubVersion to, as a pre-commit hook, write the version number to a particular file? 我可以将SubVersion作为预提交挂钩,将版本号写入特定文件吗? I know it's easy to write the version number to the file you're editing, but not so sure about writing to a totally separate file (so that it's updated on every commit, regardless of whether it was changed in that commit). 我知道很容易将版本号写入您正在编辑的文件中,但不太确定要写入一个完全独立的文件(因此无论是否在该提交中更改,它都会在每次提交时更新)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM