Gradle/Grails 应用程序 [英] Gradle / Grails application
问题描述
我一直在尝试配置 Gradle 来管理 Grails 项目几个小时,但没有成功.我在 Stack Overflow 和互联网上的其他地方找到的建议对我不起作用.
I have been trying to configure Gradle to manage a Grails project for a couple of hours with no success. The suggestions I've found here on Stack Overflow and elsewhere on the Internet didn't work for me.
你能告诉我有关如何配置 Gradle+Grails 项目的最新指导吗?理想情况下,它应该与当前版本的 Grails (2.1.0) 和 Gradle (1.1) 相关.
Could you please give me up-to-date directions on how to configure a Gradle+Grails project? Ideally it should relate to the current versions of Grails (2.1.0) and Gradle (1.1).
推荐答案
BuildScript
import org.grails.gradle.plugin.GrailsTask
buildscript {
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
dependencies {
classpath "org.grails:grails-gradle-plugin:1.1.1-SNAPSHOT"
}
}
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
version = "1.0"
grailsVersion = "2.1.0"
apply plugin: "grails"
dependencies {
['dependencies', 'resources', 'core', 'hibernate', 'plugin-datasource', 'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
compile "org.grails:grails-$plugin:2.1.0"
}
bootstrap "org.codehaus.groovy:groovy-all:1.8.6"
}
GRAILS_TASK_PREFIX = "grails-"
if (name.startsWith(GRAILS_TASK_PREFIX)) {
project.task(name, type: GrailsTask) {
command "${name - GRAILS_TASK_PREFIX}"
}
}
初始化
然后就可以做gradle init
来初始化项目结构
使用 gradle grails-[grails script]
来执行你的 grails 命令.例如:gradle grails-run-app
等价于 grails run-app
Use gradle grails-[grails script]
to execute your grails commands. For example: gradle grails-run-app
is equivalent to grails run-app
希望这有帮助!
这似乎适用于 Grails 2.3.2:
This seems to work for Grails 2.3.2:
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.grails.org/grails/repo' }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT"
}
}
repositories {
mavenCentral()
maven { url 'http://repo.grails.org/grails/repo' }
}
version = "1.0"
apply plugin: "grails"
apply plugin: 'idea'
grails {
grailsVersion = "2.3.2"
}
dependencies {
['dependencies', 'core', 'spring', 'web', 'plugin-datasource', 'plugin-domain-class', 'plugin-controllers', 'plugin-services'].each { plugin ->
compile "org.grails:grails-$plugin:2.3.2"
}
compile 'org.grails.plugins:tomcat:7.0.42'
compile 'org.grails.plugins:hibernate:3.6.10.3'
compile 'com.h2database:h2:1.3.173'
bootstrap "org.codehaus.groovy:groovy-all:2.1.9"
}
注意,在生成 Grails 包装器时抛出异常,但 gradle init
似乎正确地初始化了项目结构,否则.而且,gradle grails-run-app
似乎也能正常工作.
A note, throws Exception when generating Grails wrapper, but gradle init
seems to initialize the project structure properly otherwise. And, gradle grails-run-app
seems to work fine too.
这篇关于Gradle/Grails 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!