(Quick Reference)

3.5 版本 - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

3.5 版本

Versioning Basics

Grails has built in support for application versioning. The version of the application is set to 0.1 when you first create an application with the create-app command. The version is stored in the application meta data file application.properties in the root of the project.

To change the version of your application you can edit the file manually, or run the set-version command:

grails set-version 0.2

The version is used in various commands including the war command which will append the application version to the end of the created WAR file.

版本基础

Grails内置了对应用版本的支持。当你第一次通过create-app来创建应用的时候,其版本设置为0.1。版本信息被存储在工程根目录下的application.properties文件种。

要改变应用的版本,你可以手工修改此文件,或者运行set-version命令,比如:

grails set-version 0.2

版本信息被使用在在不同的命令中,比如war命令就会在创建的WAR文件中追加应用的版本信息。

Detecting Versions at Runtime

You can detect the application version using Grails' support for application metadata using the GrailsApplication class. For example within controllers there is an implicit grailsApplication variable that can be used:

def version = grailsApplication.metadata['app.version']

You can retrieve the the version of Grails that is running with:

def grailsVersion = grailsApplication.metadata['app.grails.version']

or the GrailsUtil class:

import grails.util.GrailsUtil
…
def grailsVersion = GrailsUtil.grailsVersion

运行期间检测版本

你可以使用GrailsApplication类来检测应用的版本信息,比如在控制器中,就有一个隐含的grailsApplication变量可用:

def version = grailsApplication.metadata['app.version']

你还可用获取到Grails的版本信息:

def grailsVersion = grailsApplication.metadata['app.grails.version']

或者通过GrailsUtil类来获取Grails的版本:

import grails.util.GrailsUtil
…
def grailsVersion = GrailsUtil.grailsVersion