No groovy compilation errors output when setting project dependencies on slf4j


(Benoit Luttringer) #1

Hello,

I want to write a program in groovy, making use of DbUnit. This library needs to have on its path the slf4j logging library.

Let me explain with example:

Here is my source file in src/main.groovy/Test.groovy:

println "test"
toto#truc

There is obviously a compilation error.

With this build.gradle :

apply plugin: 'groovy'
  repositories {
    mavenCentral()
}
  dependencies {
    groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.5'
}

I have the following output (which is correct):

:compileJava UP-TO-DATE :compileGroovy [ant:groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: [ant:groovyc] D:\DEV\GROOVY\test\src\main\groovy\Test.groovy: 3: unexpected char: ‘#’ @ line 3, column 5. [ant:groovyc]

toto#truc [ant:groovyc]

^ [ant:groovyc] [ant:groovyc] 1 error [ant:groovyc]

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileGroovy’. Cause: Forked groovyc returned error code: 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.332 secs

Now, if I modify the build.gragle by adding a dependency on slf4j and log4j binding (for instance):

apply plugin: 'groovy'
  repositories {
    mavenCentral()
}
  dependencies {
    groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.5'
    groovy group: 'org.slf4j', name: 'slf4j-api', version: '1.6.2'
    groovy group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.2'
}

Here is the output (which is not correct now, because the compilation error won’t show):

:compileJava UP-TO-DATE :compileGroovy

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileGroovy’. Cause: Forked groovyc returned error code: 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.388 secs

Thank you for your help,

Ben


(Peter Niederwieser) #2

You need to add SLF4J to the compile or runtime class path, not to the groovy class path. The latter should just contain Groovy itself. It is used to run the Groovy compiler.


(Benoit Luttringer) #3

Well, it’s way better indeed! I was convinced that the ‘groovy’ class path was the one actually used by the application too and therefore replace the ‘compile’ one as found in a java build. Thank you Peter, sorry for the loss of time.


(Peter Niederwieser) #4

It’s true that the compile configuration extends the groovy configuration. But the latter is also used to run the Groovy compiler, and that’s why you shouldn’t put anything but Groovy itself there.