Gradle / Grails应用程序 [英] Gradle / Grails application

查看:153
本文介绍了Gradle / Grails应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试配置Gradle来管理一个Grails项目几个小时而没有成功。我在这里找到的有关堆栈溢出和Internet上其他地方的建议对我来说并不适用。



请给我最新的指示配置Gradle + Grails项目?理想情况下,它应该与当前版本的Grails(2.1.0)和Gradle(1.1)相关。 >

  import org.grails.gradle.plugin.GrailsTask 

buildscript {
repositories {
mavenCentral()
mavenRepo name:grails,url:'http://repo.grails.org/grails/repo'
}
依赖关系{
classpathorg .grails:grails-gradle-plugin:1.1.1-SNAPSHOT

}
存储库{
mavenCentral()
mavenRepo名称:grails,url :'http://repo.grails.org/grails/repo'
}
version =1.0
grailsVersion =2.1.0
apply plugin:grails
依赖关系{
['dependencies','resources','core','hibernate','plugin-datasource','plugin-domain-class','plugin-tomcat','plugin -services']。each {plugin - >
compileorg.grails:grails- $ plugin:2.1.0
}
bootstraporg.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脚本] 来执行您的grails命令。例如: gradle grails-run-app 相当于 grails run-app



希望这有助于!



更新



这似乎适用于Grails 2.3。 2:

  buildscript {
repositories {
mavenCentral()
maven {url'http ://repo.grails.org/grails/repo'}
}
依赖关系{
classpathorg.grails:grails-gradle-plugin:2.0.0-SNAPSHOT
}
}
存储库{
mavenCentral()
maven {url'http://repo.grails.org/grails/repo'}
}
version =1.0
apply plugin:grails
apply plugin:'idea'
grails {
grailsVersion =2.3.2
}
依赖关系{
['dependencies','core','spring','web','plugin-datasource','plugin-domain-class','plugin-controllers','plugin-services '] .each {plugin - >
compileorg.grails:grails- $ plugin:2.3.2

compile'org.grails.plugins:tomcat:7.0.42'
compile'org。 grails.plugins:hibernate:3.6.10.3'
compile'c​​om.h2database:h2:1.3.173'
bootstraporg.codehaus.groovy:groovy-all:2.1.9
在生成Grails包装器时抛出异常,但是 gradle init $ b $> / code>似乎正确地初始化项目结构,否则。而且, gradle grails-run-app 似乎也能正常工作。


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.

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}"
    }
}

Initialize

Then you can do gradle init to initialize the project structure

Commands

Use gradle grails-[grails script] to execute your grails commands. For example: gradle grails-run-app is equivalent to grails run-app

Hope this helps!

Update

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"
}

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆