Maven - Can't Resolve Java Class in Groovy

Error Importing Java Class

I just came across this error using Maven and Spock (using the mavenplus-plugin to compile groovy code).

[INFO] --- gmavenplus-plugin:1.5:testCompile (default) @ my-project ---
[INFO] Using Groovy 2.4.6 to perform testCompile.
[ERROR] Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:testCompile (default) on project my-project: Error occurred while calling a method on a Groovy class from classpath. InvocationTargetException: startup failed:
[ERROR] /path/to/MySpec.groovy: 5: unable to resolve class com.mypackage.TestClass
[ERROR] @ line 5, column 1.
[ERROR] import com.mypackage.TestClass
[ERROR] 1 error
[ERROR] -> [Help 1]

Java File in Groovy Folder

The Java class being imported into a groovy class (a Spock test) was located in the test/groovy folder instead of the test/java folder meaning it wasn’t being compiled by Maven in the right order.

An easy fix: move the Java class file to the test/java folder!

tags fixjavaspock