How can I use the Gradle Tooling API from a Grails Controller?


(Timothy Montague) #1

Currently, I am developing a Grails application that requires the use of gradle to compile C/C++ files. I have already built the C/C++ gradle build script.

I would like to “trigger” the C/C++ builds from a Grails controller. I asked the question on Stackoverflow - http://stackoverflow.com/questions/10971727/how-do-i-trigger-a-gradle-build-from-a-grails-controller , and I was directed to gradle embedding with the tooling API that was released in gradle 1.0-rc-3.

I visited the JavaDoc/GoovyDoc and looked over the sample examples. But they don’t satisfy my question - “How do I integrate Gradle as a service for Grails, and then use a Grails controller to trigger a Gradle build for a C/C++ compile (or any other language compile)?”.

As I can NOT find many real-world use cases, I am wondering if someone could extensively elaborate and provide an example (or two) explaining embedding, the tooling API, and how to best accomplish this goal.


(Adam Murdoch) #2

I can’t help you with the grails part - perhaps others can.

The sample in ‘$gradleHome/samples/toolingApi/build’ shows you how to run a Gradle build from your application:

  • You need to bundle the tooling API jar and its dependencies in your application. This doesn’t need to match the Gradle version you want to build with. The tooling API is forwards and backwards compatible. * In your application, create a ‘GradleConnector’ instance, configure it as required. Usually you don’t need any configuration. * Use the ‘GradleConnector’ to create a ‘ProjectConnection’ for the project you want to build. * Use the ‘ProjectConnection’ to create a ‘BuildLauncher’. * Configure the ‘BuildLauncher’ with the name of the task(s) you want to run, and any other configuration you need. * Run the build using ‘BuildLauncher.run()’.

(Timothy Montague) #3

Maybe putting this in the controller will accomplish the task (testing it now): -------------------------------------------------------------------------------------------------------------

import org.gradle.tooling.*;

ProjectConnection connection = GradleConnector.newConnector()

.forProjectDirectory(new File(“project_directory”)).connect();

try {

BuildLauncher build = connection.newBuild();

// select tasks to run

build.forTasks(“build”,“upload”);

build.run();

} finally {

connection.close(); }


But it still doesn’t solve my second question: What is the best way to incorporate Gradle into my Grails application as a service, and use it to build outside projects?


(Luke Daley) #4

can you please clarify what features you need. Based on your wording it seems that moving that code into a service would suffice.


(Timothy Montague) #5

Luke,

I have already built a gradle.build file which successfully runs. The build file compiles C/C++.

I would like to incorporate the Gradle libraries (not sure which ones I need) into the Grails Lib folder, so that I can import the org.gradle.tooling api into a Grails service. I would then like to call this service from the Grails controller and trigger the Gradle build.

I currently have the following code in a controller (which I will probably need to move into a service): … import java.lang.Object import org.gradle.tooling.BuildLauncher import org.gradle.tooling.GradleConnector import org.gradle.tooling.ProjectConnection

String projectDir = “my\\directory\\path\”

GradleConnector connector = GradleConnector.newConnector() connector.forProjectDirectory(new File(projectDir)) ProjectConnection connection = connector.connect()

try {

// Configure the build

BuildLauncher launcher = connection.newBuild()

launcher.forTasks(“build”,“upload”)

launcher.run() } finally {

connection.close() } … I also have the “gradle-tooling-api-1.0-rc-3.jar” and the “gradle.launcher-1.0-rc-3.jar” in the Grails ‘Lib’ folder. … When I try to run this I get the following error: [“http-bio-8080”-exec-10] ERROR errors.GrailsExeptionResolver - ClassNotFoundException occurred - org.gradle.api.internal.concurrent.SynchronizedServiceRegistry.

… I am wonder what I need in the Lib folder, what code I need in the service, and what code I need in the controller - so that I can trigger my gradle build file.

Thank you for your time.

Timothy F. Montague


(Luke Daley) #6

Use this Gradle build to download the dependencies you need.

repositories {
    maven {
        url 'http://repo.gradle.org/gradle/libs-releases-local'
    }
    mavenCentral()
}
  def toolingApiVersion = "1.0"
  configurations {
    toolingApi
}
  dependencies {
    toolingApi ("org.gradle:gradle-tooling-api:${toolingApiVersion}") {
        exclude module: "slf4j-api"
    }
}
  task libs(type: Sync) {
    from configurations.toolingApi
    into "libs"
}

Run ‘gradle libs’, then the jars will be in the ‘libs’ directory.

As for what code goes in the controller vs. service, that’s purely a design decision on your part. It doesn’t matter to the tooling API.


(Timothy Montague) #7

Not working. I put the code into a file called “gradle.build” and in a directory called “xyz”, then from inside the directory, I executed the build with “gradle libs”. I tried creating a sub-directory called libs as well, and then ran the code - but keep getting the same error.

FAILURE: Could not determine which tasks to execute. Task ‘libs’ not found in root project “xyz”.


(Luke Daley) #8

Please check that there’s no copy/paste error. There is definitely a libs task in that script above.


(Timothy Montague) #9

No copy and paste error. The file keeps failing to build.


(Luke Daley) #10

The file should be called ‘build.gradle’, not ‘gradle.build’.


(Timothy Montague) #11

Ah (not my proudest moment). The build file now works.


(Timothy Montague) #12

I still can’t get this to work. This is what I have:

I used the build script by Luke Daley. I placed the output - jar files - into my Grails application, lib directory: - gradle-tooling-api-1.0.jar - gradle-core-1.0.jar - gradle-wrapper-1.0.jar - gradle-base-services-1.0.jar

I put the following code into my grails controller (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 have a folder called “demo” on my desktop with a file inside called “build.gradle”.

tasks hello {
  println "hello world"
}

I have tested the controller, the “run” action, and I don’t get errors for the gradle methods. So I assume I’m missing some files needed by Gradle or Grails to make this work.

Grails is happy with the syntax in the controller. But, when I run the code - I get the following errors… (in the next post)


(Timothy Montague) #13

new run ------------------------------------- Building file… 15:10:36,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 15:10:36,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] 15:10:36,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml] 15:10:36,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration. 15:10:36,312 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.DateConverter] for keyword [d] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.DateConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.DateConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted Caused by: java.lang.ClassNotFoundException: com.springsource.loaded.ri.ReflectiveInterceptor

at at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at at java.security.AccessController.doPrivileged(Native Method)

at at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

at at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

at … 44 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [d] is not a valid conversion word 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.ThreadConverter] for keyword [thread] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.ThreadConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.ThreadConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [thread] is not a valid conversion word 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.LevelConverter] for keyword [level] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LevelConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LevelConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [level] is not a valid conversion word 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.LoggerConverter] for keyword [logger] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LoggerConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LoggerConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [logger] is not a valid conversion word 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MessageConverter] for keyword [msg] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.MessageConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.MessageConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [msg] is not a valid conversion word 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.LineSeparatorConverter] for keyword [n] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LineSeparatorConverter

at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LineSeparatorConverter

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)

at at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)

at at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:61)

at at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:90)

at at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)

at at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:27)

at at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)

at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)

at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:54)

at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)

at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)

at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)

at at org.gradle.tooling.internal.provider.DefaultConnection.(DefaultConnection.java:43)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

at at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)

at at org.gradle.api.internal.DirectInstantiator.newInstance(DirectInstantiator.java:40)

at at org.gradle.util.ServiceLocator$ServiceFactory.newInstance(ServiceLocator.java:141)

at at org.gradle.util.ServiceLocator$ServiceFactory.create(ServiceLocator.java:135)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:60)

at at org.gradle.tooling.internal.consumer.loader.DefaultToolingImplementationLoader.create(DefaultToolingImplementationLoader.java:35)

at at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)

at at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:42)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.onStartAction(LazyConnection.java:135)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:118)

at at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)

at at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)

at at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)

at at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)

at at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: com/springsource/loaded/ri/ReflectiveInterceptor

at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:50)

at … 43 common frames omitted 15:10:36,328 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@18c7eb0 - [n] is not a valid conversion word %PARSER_ERROR[d] [%PARSER_ERROR[thread]] %PARSER_ERROR[level] %PARSER_ERROR[logger] - %PARSER_ERROR[msg]%PARSER_ERROR[n]| Error 2012-06-16 15:10:36,515 [“http-bio-8080”-exec-8] ERROR errors.GrailsExceptionResolver - ClassNotFoundException com.springsource.loaded.ri.ReflectiveInterceptor. Stacktrace follows: Message: com.springsource.loaded.ri.ReflectiveInterceptor

Line | Method ->> 366 | run

in java.net.URLClassLoader$1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

|

355 | run

in

‘’ |

354 | findClass . . . . . in java.net.URLClassLoader |

423 | loadClass

in java.lang.ClassLoader |

356 | loadClass . . . . . in

‘’ |

85 | findFactoryMethods


(Luke Daley) #14

When posting stacktraces, please wrap it in <code> tags. It’s very difficult to read otherwise. Please repost the stacktrace with this.


(Timothy Montague) #15

Sure. The stacktrace is now in code tags.


(Timothy Montague) #16

I’m using Grails 2.0.0 -

I also tried this from my controller:

@GrabResolver(name="gradle", root="http://repo.gradle.org/gradle/libs-releases-local")
@Grab("org.gradle:gradle-tooling-api:1.0-milestone-9")
@Grab("org.slf4j:slf4j-simple:1.6.4")
import org.gradle.tooling.BuildLauncher
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection
  class consoleController {
  }

…and I get the same stacktrace error.


(Luke Daley) #17

Spring loaded, which is the technology that enables hot reloading of classes in Grails, is causing the problem here.

It does deep modifications to classloading, and this is impacting the loading of the tooling API consumer in some way.

It would be extremely helpful if you could provide a minimal project that has this behaviour. We could then work with the SpringSource folks to sort this out.


(Timothy Montague) #18

Sure. How do you want me to provide this minimum project? I can email the zip, or you can follow the instructions below.

1.) Install Gradle, Grails, and Java. And make sure your paths are set correctly so that you can call the gradle and grails programs from the command line.

2.) Create a new grails app called gradleEmbed in any directory you prefer -

grails create-app gradleEmbed

3.) Run the build.gradle file (provided above by Luke Daley), and move the contents created in the Libs folder (should be 4 jar files) into the lib folder - “./grailsEmbed/lib” directory. - gradle-core-1.0.jar - gradle-tooling-api-1.0.jar - gradle-wrapper-1.0.jar - gradle-base-services-1.0.jar

4.) Navigate to the directory “./grailsEmbed/grails-app/config” and add the following line to the file UrlMappings.groovy - in the closure called: static mappings = { // add line in here }

"/run"(controller: "console", action: "run")

5.) Navigate to the directory “./grailsEmbed/grails-app/controllers” and add the file ‘consoleController.groovy’ that contains the following code:

import org.gradle.tooling.BuildLauncher
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection
  class consoleController {
    def run = {
  println "Building file..."
     String projectDir = System.properties['base.dir'] + "\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()
  }
      // Success
  response.sendError(200,'Done')
 }
  }

6.) Navigate to the directory “./grailsEmbed” and create a new directory called “demo”, and create a file within that directory called “build.gradle” with the following code:

task hello {
 println "Hello world"
}

7.) Navigate to the directory “./grailsEmbed” and execute the following command:

grails run-app

8.) Open a web browser, and go to the following url - “http://localhost:8080/grailsEmbed/run” and watch the stack trace in the terminal.


(Timothy Montague) #19

Luke Daley,

The build does not run correctly due to a java.lang.classNotFoundException caused by com.springsource.loaded.ri.ReflectiveInterceptor. The reloading agent is getting in the way of the gradle build.

Executing the following command, I was able to use the gradle tooling API from the grails controller -

grails -noreloading run-app

I am not sure if this is a problem that is specific to Grails 2.0.0. I am going to check if this issue is solved in the latest Grails release.


(Markus Schneider) #20

Hi Timothy,

have you found a solution for this issue?

-markus