Gradle / Grails application

后端 未结 1 1085
-上瘾入骨i
-上瘾入骨i 2020-12-08 16:44

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

相关标签:
1条回答
  • 2020-12-08 17:16

    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.

    0 讨论(0)
提交回复
热议问题