grails-gradle-plugin-archived icon indicating copy to clipboard operation
grails-gradle-plugin-archived copied to clipboard

Javassist Enhancement failed error message when running test task

Open craigburke opened this issue 10 years ago • 25 comments

I get an error message when I try to run the test task in a project with at least one domain class (I get the same error for every domain class in the project). The tests do in fact run though:

| Error 2014-08-19 10:21:39,182 [main] ERROR pojo.BasicLazyInitializer  - Javassist Enhancement failed: com.craigburke.gradle.Foo
Message: No such property: hasProperty for class: groovy.lang.MetaClassImpl
   Line | Method
->> 102 | doCall       in _GrailsTest$_run_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    32 | doCall       in TestApp$_run_closure1
|    57 | invokeMethod in org.grails.launcher.util.ReflectionUtils
|   409 | launch       in org.grails.launcher.context.DelegatingGrailsLaunchContext
|    32 | launch . . . in org.grails.launcher.ReflectiveGrailsLauncher
|    27 | launch       in org.grails.launcher.InProcessGrailsLauncher
|    62 | run . . . .  in org.grails.launcher.Main
^    38 | main         in     ''
| Tests PASSED - view reports in /Users/craig/src/grails-gradle/build/test-results

A minimal build.gradle file to reproduce the issue:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:2.1.0"
    }
}

version "0.1"
group "com.craigburke.gradle"

apply plugin: "grails"

repositories {
    jcenter()
    grails.central()
}

grails {
    grailsVersion = '2.4.3'
    groovyVersion = '2.3.6'
}

dependencies {
    bootstrap 'org.grails.plugins:tomcat:7.0.55'
    runtime('org.grails.plugins:hibernate4:4.3.5.5') {
                exclude module: 'xml-apis'
        }
}

After adding the domain class Foo.groovy to a newly initialized grails project then I get the above error

package com.craigburke.gradle

class Foo {
    String bar
}

I can send along the full example project if that would be helpful.

craigburke avatar Aug 19 '14 14:08 craigburke

Removing asset-pipeline dependency. It's necessary for the grails-run-app task but the issue still remains on the test task without it. Hopefully that helps narrow down any dependency issue.

craigburke avatar Aug 19 '14 14:08 craigburke

It looks like it comes from the hibernate4 plugin...as soon as I remove that the error goes away.

johnrengelman avatar Aug 19 '14 14:08 johnrengelman

is there a global exclude in Grails that we are missing?

johnrengelman avatar Aug 19 '14 14:08 johnrengelman

FYI. This may be related to known issues mentioned in the release notes.

Recently, I was able to convert an app (v2.4.2) from maven to gradle using this plugin successfully. I am using 4.3.5.5 version of hibernate4

dmahapatro avatar Aug 19 '14 15:08 dmahapatro

@dmahapatro so the FreshRuntime annotation on your tests resolved this for you or did you have to do something else?

craigburke avatar Aug 19 '14 15:08 craigburke

No, I am using 2.4.2 and did not use any of @FreshRuntime or @DirtiesRuntime. One way to confirm this, is if you can use Grails 2.4.2 and see if you still get the same issue. @craigburke. With that the groovyVersion downgrades to 2.3.3

dmahapatro avatar Aug 19 '14 15:08 dmahapatro

@dmahapatro I gave that a try, same result unfortunately.

craigburke avatar Aug 19 '14 15:08 craigburke

I am thoroughly confused. If I add -PgrailsArgs="--stacktrace" to the Gradle command then I don't get the error.

johnrengelman avatar Aug 19 '14 15:08 johnrengelman

@johnrengelman ok that's just weird.

craigburke avatar Aug 19 '14 15:08 craigburke

@johnrengelman -PgrailsArgs="--stacktrace"still gives me the error actually.

craigburke avatar Aug 19 '14 16:08 craigburke

This is what I'm running:

$ rm -r build buildPlugins && gradle grails-test-app -PgrailsEnv=test -PgrailsArgs="--stacktrace"

can you post your entire project somewhere so I'm looking at exactly the same thing?

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

@craigburke Passed for me for a new grails 2.4.2 app with the same config you have in build.gradle. Will test the same in 2.4.3. How are you running your test? I used

gradle test

dmahapatro avatar Aug 19 '14 16:08 dmahapatro

Here's my output:

➜  grails-test  rm -r build buildPlugins && gradle grails-test-app -PgrailsEnv=test -PgrailsArgs="--stacktrace"
:grails-test-app
| Loading Grails 2.4.3
| Configuring classpath
| Running pre-compiled script
| Running pre-compiled script.
| Environment set to test
| Environment set to test.
| Environment set to test..
| Environment set to test...
| Environment set to test....
| Environment set to test.....
| Installing zip scaffolding-2.1.2.zip...
| Installing zip scaffolding-2.1.2.zip....
| Installing zip scaffolding-2.1.2.zip.....
| Installed plugin scaffolding-2.1.2
| Installed plugin scaffolding-2.1.2.
| Installed plugin scaffolding-2.1.2..
| Installed plugin scaffolding-2.1.2...
| Installed plugin scaffolding-2.1.2....
| Installed plugin scaffolding-2.1.2.....
| Installing zip hibernate4-4.3.5.5.zip...
| Installing zip hibernate4-4.3.5.5.zip....
| Installing zip hibernate4-4.3.5.5.zip.....
| Installed plugin hibernate4-4.3.5.5
| Installed plugin hibernate4-4.3.5.5.
| Installed plugin hibernate4-4.3.5.5..
| Installed plugin hibernate4-4.3.5.5...
| Installed plugin hibernate4-4.3.5.5....
| Installed plugin hibernate4-4.3.5.5.....
| Installing zip tomcat-7.0.55.zip...
| Installing zip tomcat-7.0.55.zip....
| Installing zip tomcat-7.0.55.zip.....
| Installed plugin tomcat-7.0.55
| Installed plugin tomcat-7.0.55.
| Installed plugin tomcat-7.0.55..
| Installed plugin tomcat-7.0.55...
| Installed plugin tomcat-7.0.55....
| Installed plugin tomcat-7.0.55.....
| Compiling 17 source files

| Compiling 17 source files.
| Compiling 17 source files..
| Compiling 17 source files

| Compiling 17 source files.
| Compiling 17 source files..
| Compiling 17 source files...
| Compiling 17 source files....
| Compiling 17 source files.....
| Compiling 8 source files
| Compiling 8 source files.
| Compiling 8 source files..
| Compiling 8 source files...
| Compiling 8 source files....
| Compiling 8 source files.....
| Compiling 1 source files
| Compiling 1 source files.
| Running 2 unit tests...
| Running 2 unit tests... 1 of 2
| Completed 1 unit test, 0 failed in 0m 2s
| Tests PASSED - view reports in /Users/jengelman/workspace/personal/gradle-stuff/grails-test/build/test-results

BUILD SUCCESSFUL

Total time: 20.07 secs

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

gradle test works fine for me as well.

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

Yes I see the issue using gradle grails-test-app.

2014-08-19 12:08:06,748 [main] ERROR pojo.BasicLazyInitializer  - Javassist Enhancement failed: com.example.Foo
Message: No such property: hasProperty for class: groovy.lang.MetaClassImpl
   Line | Method
->> 102 | doCall       in _GrailsTest$_run_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    32 | doCall       in TestApp$_run_closure1
|    57 | invokeMethod in org.grails.launcher.util.ReflectionUtils
|   409 | launch       in org.grails.launcher.context.DelegatingGrailsLaunchContext
|    32 | launch . . . in org.grails.launcher.ReflectiveGrailsLauncher
|    27 | launch       in org.grails.launcher.InProcessGrailsLauncher
|    62 | run . . . .  in org.grails.launcher.Main
^    38 | main         in     ''```

dmahapatro avatar Aug 19 '14 16:08 dmahapatro

it's somehow related to the GrailsTestTask.getArgs() method. When I comment that method out, then the error occurs when running tests.

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

Ok, I believe it's because getArgs() method in GrailsTask by default returns a null instead of an empty String.

That's causing a problem here: https://github.com/grails/grails-gradle-plugin/blob/8fb1f60a0e158d06f6ff3baed9e9e8d99ba8d6b8/src/main/groovy/org/grails/gradle/plugin/tasks/GrailsTask.groovy#L206 because that is actually evaluating to the String: null --non-interactive.

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

And it works fine when you use gradle test because that task is a GrailsTestTask, whereas gradle grails-test-app is a TaskRule that is created using a standard GrailsTask. GrailsTestTask overrides the getArgs() method and returns at minimum ''.

johnrengelman avatar Aug 19 '14 16:08 johnrengelman

Still running into the same issue with either gradle test or gradle grails-test-app Going to clean everything out, nuke my ~/.gradle folder and start a new project.

@johnrengelman I noticed from your output that your project included a couple unit tests. Should that matter or are you seeing the same result with a clean project that has no tests?

craigburke avatar Aug 20 '14 15:08 craigburke

Guess I don't know on that one...didn't try.

I would nuke build and buildPlugins in your project folder....~/.gradle shouldn't have any impact.

Also, have you commented out the dependencies in BuildConfig.groovy?

johnrengelman avatar Aug 20 '14 15:08 johnrengelman

I had it commented in my original project, but not my test. I tried that and nuking build and buildPlugins doesn't seem to help.

I did throw a new project that shows exactly what I'm using. Perhaps I'm missing a step or something jumps out at your there? https://github.com/craigburke/grails-gradle-test

Thanks for your patience, I really appreciate your help :)

craigburke avatar Aug 20 '14 16:08 craigburke

Hmm. Seems to still happen if there are no tests defined. That's why your project spits the error out and mine doesn't.

johnrengelman avatar Aug 27 '14 13:08 johnrengelman

And it's only an issue with the unit test phase.

johnrengelman avatar Aug 27 '14 13:08 johnrengelman

Yeah I was just going to ask that. I had functional tests in my original project but no unit tests.

craigburke avatar Aug 27 '14 13:08 craigburke

You're definitely on to something. If I add a simple unit test then the message goes away for me.

craigburke avatar Aug 27 '14 13:08 craigburke