简体   繁体   中英

How do I trigger a gradle build from a grails controller?

How do I build an outside Gradle project from a Grails controller? Grails 2.0.0

UPDATE : I emailed Adam Murdoch (co-founder of gradle) about this question: http://forums.gradle.org/gradle/topics/how_can_i_use_the_gradle_tooling_api_from_a_grails_controller

While, I don't have a direct answer to this question, I do have a solution. Any further insights on this subject would be greatly appreciated.


I used a gradle build script provided by Luke Daley. Ran build.gradle, and it output 4 jar files needed for gradle tooling api. I then put these into my Grails lib folder.

I then wrote the following code into my grails controller called consoleController.groovy.

import org.gradle.tooling.BuildLauncher
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection

class consoleController {
   def run = {
       println "new run -------------------------------------"
       println "Building file..."

       String projectDir = "C:\\Documents and Settings\\Administrator\\Desktop\\demo"
       GradleConnector connector = GradleConnector.newConnector()
       connector.forProjectDirectory(new File(projectDir))

       ProjectConnection connection = connector.connect()
       try {
           BuildLauncher launcher = connection.newBuild()
           launcher.forTasks("hello")
           launcher.run()
       } finally {
           connection.close()
       }
    }
 }

I also created a directory called "demo" - with a build.gradle file.

task hello {
    println "hello world"
}

I get the following stack trace - errors: PLEASE SEE - http://forums.gradle.org/gradle/topics/how_can_i_use_the_gradle_tooling_api_from_a_grails_controller

Stack trace is too long for StackOverflow.com.

You may visit the post entitled http://forums.gradle.org/gradle/topics/how_can_i_use_the_gradle_tooling_api_from_a_grails_controller which provides directions for setting-up a minimal grails project for embedding the grails tooling API, and allows a user to trigger builds from a grails controller.

Grails 2.0.0 should fully support the Gradle tooling API out of the box, but Spring Loaded a technology that enables hot-reloading of classes gets in the way of the gradle tooling API, and throws an error: java.lang.ClassNotFoundException: com.springsource.loaded.ri.ReflectiveInterceptor - when trying to build.

Running the grails app with the -noreloading flag, solves the problem.

> grails -noreloading run-app

An alternative to Grails embedding, that would still allow builds to be triggered from a Grails controller would be to use a Continuous Integration server that supports REST, such as Jenkins (TeamCity, Bamboo, CruiseControl, etc.); while, this is not a direct solution to this question, these enterprise applications provide an alternative to Gradle embedding and are probably better suited for enterprise offerings.

Cheers, TFM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM