Grails cant use Spock framework? - testing

I am currently working on a project that had started with no TDD in place and now I have taken the following steps to start using Spock for Unit and Integration testing on this project:
Added the following to the buildconfig:
test ":spock:0.7"
Then created a spec at "test/unit/MYCLASSNAME" called MyfunctionControllerSpec as shown below:
import grails.test.mixin.*
import spock.lang.Specification
class MyfunctionControllerSpec extends Specification {
void "list() should return no results with no records in DB"() {
given:
def model = controller.list()
expect:
model.taskInstanceList.size() == 0
model.taskInstanceTotal == 0
}
}
However I am getting the following errors with the Specification import line:
Groovy:unable to resolve class spock.lang.Specification
I don’t understand what I am doing wrong, have I imported or install Spock wrong?
Thanks in advance
EDIT*
I have tried the suggestion below and then the solution wont run and it still doesnt recognise the Specification class, even when I start typing "inport spo" and press cntrl+space nothing comes up as if it cant even recogise the plugin either:
Loading Grails 2.1.0
| Configuring classpath
| Downloading: spock-grails-support-0.7-groovy-2.0.pom.sha1
| Downloading: spock-core-0.7-groovy-2.0.pom.sha1
| Downloading: spock-grails-support-0.7-groovy-2.0.jar.sha1
| Downloading: spock-core-0.7-groovy-2.0.jar.sha1.
| Environment set to development....
| Error Error loading event script from file [/media/system/workspace/sms_bskyb_New_V2(Dynam Messages)/plugins/tool-ui/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/database-migration-1.1/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/tomcat-2.1.0/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/spock-0.7/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Error Error loading event script from file [/home/system/.grails/2.1.0/projects/sms_bskyb/plugins/webxml-1.4.1/scripts/_Events.groovy] startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)
| Environment set to development.....
| Packaging Grails application.
| Error Fatal error during compilation org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/system/.grails/ivy-cache/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
1 error
(Use --stacktrace to see the full trace)

You are using Grails 2.1.0 whereas Groovy 2.0 was introduced in Grails 2.2.0 and above. Hopefully you do not need to explicit dependency org.spockframework:spock-grails-support:0.7-groovy-2.0. Only use as below:
plugins{
test ":spock:0.7"
}
In case you still find an issue then isolate the problem by creating a fresh new bare bone grails app and install the plugin as mentioned in the plugin docs. Try to see if there is any classpath clash. If the problem still exists, then clear ivy-cache and/or .m2 and retry.

I almost answered this here, but I see that you are using Grails 2.1.
For others that are getting this error with Grails 2.2.x see this answer

Related

Gradle annotation processor order (Android)

I'm writing a library based on code generation.
This library generating dagger's module via annotations. How do I run my annotation processor before dagger's code generation?
Now it crashes on build because dagger trying to build the component before modules was generated.
Error:
.ktC:\Users\syncended\AndroidStudioProjects\Daggerblade\app\build\tmp\kapt3\stubs\debug\dev\syncended\daggerblade\AppComponent.java:6: error: cannot find symbol
#dagger.Component(modules = {BookModule.class})
^
symbol: class BookModuleC:\Users\syncended\AndroidStudioProjects\Daggerblade\app\build\tmp\kapt3\stubs\debug\dev\syncended\daggerblade\AppComponent.java:7: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract interface AppComponent {
^Attempt to reopen a file for path C:\Users\syncended\AndroidStudioProjects\Daggerblade\app\build\generated\source\kapt\debug\dev\syncended\blade\BookModule.kt
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
* Try:

Gradle, error: module not found: kotlin.logging

These are my dependencies in build.gradle.kts:
implementation("io.github.microutils:kotlin-logging:1.7.8")
implementation("org.slf4j:slf4j-api:1.7.29")
Then in module-info.java:
requires kotlin.logging;
All the rest works fine with the Java modular approach
However whenever I try to build, then I get:
> Task :compileJava FAILED
6 actionable tasks: 6 executed
C:\Users\elect\IdeaProjects\assimp\src\main\java\module-info.java:13: error: module not found: kotlin.logging
requires kotlin.logging;
What am I doing wrong?
Automatic module name
PS C:\Users\elect> jar --file=C:\Users\elect\.gradle\caches\modules-2\files-2.1\io.github.microutils\kotlin-logging-jvm\2.0.3\acd404001442be5d98fbaa7ff9df83041cba70fe\kotlin-logging-jvm-2.0.3.jar --describe-module
No module descriptor found. Derived automatic module.
kotlin.logging.jvm#2.0.3 automatic
requires java.base mandated
contains mu
contains mu.internal

MainActivity error while importing package: `react-native-google-vr-panorama`

I am getting an error when I import a package into my JS file:
import GoogleVRPanorama, { PanoramaView } from 'react-native-google-vr-panorama'
Error:
This error I get with all the VR 360 components I try to import.
Edit-1:
I did follow the installation steps but I didn't rebuild the app
MainApplication.java: MainApplication
So when I rebuild the app, getting the following error:
C:\Users\cherry\Test03\node_modules\react-native-google-vr-panorama\android\src\main\java\com\xebia\googlevrpanorama\RNGoogleVRPanoramaPackage.java:14:
error: method does not override or implement a method from a supertype
#Override
^ Note: C:\Users\cherry\Test03\node_modules\react-native-google-vr-panorama\android\src\main\java\com\xebia\googlevrpanorama\RNGoogleVRPanoramaView.java
uses unchecked or unsafe operations. Note: Recompile with
-Xlint:unchecked for details. 1 error :react-native-google-vr-panorama:compileReleaseJavaWithJavac FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':react-native-google-vr-panorama:compileReleaseJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Sounds like you either
1. Did not finish the install steps, i.e. adding lines to MainApplication etc., see https://github.com/XebiaStudio/react-native-google-vr-panorama/blob/master/README.md#installation for details
or
2. Did not rebuild the app with react-native run-android.

Multi-dimension Android project won't build - ProcessInfoBuilder$JavaProcessInfoImpl.getExecutable throws UnsupportedOperationException

i've got a rather large, multi-dimension Android app that i'm trying to upgrade from Dagger 1 to Dagger 2. i've made all the code changes i believe need to be made to support the upgrade, but now when i build the app i'm getting the following exception (during the transformClassesWithMultidexlistForXXX task):
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForMyFlavorAndDimensionDebug'.
> java.lang.UnsupportedOperationException (no error message)
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForMyFlavorAndDimensionDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
...(snip)...
Caused by: java.lang.UnsupportedOperationException
at com.android.ide.common.process.ProcessInfoBuilder$JavaProcessInfoImpl.getExecutable(ProcessInfoBuilder.java:349)
at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:74)
at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49)
at com.android.builder.core.AndroidBuilder.createMainDexList(AndroidBuilder.java:1426)
...(snip)...
... 68 more
BUILD FAILED
Total time: 5 mins 5.179 secs
Stopped 0 compiler daemon(s).
digging into the source, ProcessBuilder.JavaProcessInfoImpl.getExecutable() simply throws an UnsupportedOperationException.
i'm using version 2.2.3 of the Android Gradle plug-in.
has anyone else run into this issue? have i done something in error to lead me down this path?
any thoughts or suggestions would be greatly appreciated!
*********************** UPDATE ***********************
i managed my way around this issue by downgrading from Dagger 2.8 —> 2.7.

NullPointerException org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:37)

Got the following stacktrace when launching gradle 1.1, anyone know how to resolve them:
Exception in thread "main" java.lang.NullPointerException
at org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:37)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:28)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
I think the automatic unzip of the dists/gradle-1.1-bin/13d7lnhcrghv2i5e54el41jpgr/gradle-1.1-bin.zip might be failing. I checked permissions and that I have access to that directory.
If I unzip manually, then I get the following error:
Exception in thread "main" java.lang.RuntimeException: Gradle distribution 'http://services.gradle.org/distributions/gradle-1.1-bin.zip' contains too many directories. Expected to find exactly 1 directory.
at org.gradle.wrapper.Install.createDist(Install.java:73)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
I did a google search for gradle nullpointerexception and it mentioned the JAVA_HOME needs to be set for compiling, but I've already checked it is set correctly and been able to compile stuff with ant in that environment.
I was getting exactly same error and I changed the version of gradle that I was using. Inside my gradle-wrapper.properties, changed version 2.4 to 2.2.1 and error is gone.