grails / grails-gradle-plugin-archived

142 stars 40 forks source link

Javassist Enhancement failed error message when running test task #118

Open craigburke opened 10 years ago

craigburke commented 10 years ago

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 commented 10 years ago

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.

johnrengelman commented 10 years ago

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

johnrengelman commented 10 years ago

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

dmahapatro commented 10 years ago

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

craigburke commented 10 years ago

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

dmahapatro commented 10 years ago

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

craigburke commented 10 years ago

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

johnrengelman commented 10 years ago

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

craigburke commented 10 years ago

@johnrengelman ok that's just weird.

craigburke commented 10 years ago

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

johnrengelman commented 10 years ago

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?

dmahapatro commented 10 years ago

@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
johnrengelman commented 10 years ago

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 commented 10 years ago

gradle test works fine for me as well.

dmahapatro commented 10 years ago

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     ''```
johnrengelman commented 10 years ago

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

johnrengelman commented 10 years ago

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 commented 10 years ago

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 ''.

craigburke commented 10 years ago

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?

johnrengelman commented 10 years ago

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?

craigburke commented 10 years ago

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 :)

johnrengelman commented 10 years ago

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 commented 10 years ago

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

craigburke commented 10 years ago

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

craigburke commented 10 years ago

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