在GSP中使用Gradle使用错误编码使用Grails应用程序构建

时间:2016-03-15 20:50:38

标签: grails gradle

我有一个Grails应用程序,当通过Gradle构建脚本构建WAR时,视图以错误的编码呈现(即法语字符显示不正确)。

直接从grails运行应用程序或构建时,所有内容都可以正确呈现。

所以,具体来说:

Grails - grails war正常工作

Gradle - gradle grails-war -PgrailsEnv=prod提供不正确的编码。

build.gradle文件:

buildscript {
    repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }
        maven  {
            url "http://repo1.maven.org/maven2"
        }
    }
    dependencies {
        classpath 'org.grails:grails-gradle-plugin:2.1.2'
    }
}

apply plugin: 'grails'

version = 1.0

grails {
    grailsVersion = '2.4.3'
    groovyVersion = '2.4.3' 
}

repositories {
    jcenter {
        url "http://jcenter.bintray.com/"
    }   
    grails.central()
}

dependencies {
    bootstrap 'org.grails.plugins:tomcat:7.0.50'
    compile "org.grails.plugins:cache:1.1.7"
    compile "org.grails.plugins:rest:0.8"
    runtime ("org.grails.plugins:hibernate4:4.3.5.5") {
        exclude module: 'xml-apis'
    }
    runtime "org.grails.plugins:database-migration:1.4.0"

    compile fileTree(dir: 'lib', include: '*.jar')
}

感谢任何帮助,谢谢。

2 个答案:

答案 0 :(得分:0)

结帐mr.haki's post about Gradle encodinganswers for similar question

  

在我们的项目中为所有编译任务设置编码属性   可以使用TaskContainer上的withType()方法来查找所有任务   类型编译。然后我们可以在配置中设置编码   封闭:

compileJava.options.encoding = 'UTF-8'

tasks.withType(Compile) {
    options.encoding = 'UTF-8'
}

另请参阅section Environments in official docs

答案 1 :(得分:0)

我遇到了与HTML模板相同的问题。

为gradle构建添加-Dfile.encoding=UTF-8作为JVM参数修复了模板的问题。

对于*.gsp个文件,您可以添加

<%@ page contentType="text/html;charset=UTF-8" %>

到您文件的<head>部分。