Gradle compile issues migrating from Groovy 2.4.4 to 4.0.3

INFO:
I built this project awhile ago with Groovy 2.4.4 that utilizes the groovy-all-2.4.4.jar file. The newest version of Groovy is 4.0.3 that doesn’t have a pre-compiled “all” jar file, I have to include the needed jars manually.

ISSUE:
When I compile with the original dependency of just “groovy-2.4.4-all.jar”, there are no issues with the build and I get a build JAR file as needed.

However, when I update the dependencies to use Groovy 4.0.3, I’m getting the dreaded “unable to resolve class” on classes that had no issues when compiled with Groovy 2.4.4-all jar.

I can get that part, but what is stumping me is that I cannot figure out if this is a Groovy or Gradle issue.

Any suggests on pointers of how to go about addressing this build issue?

VERSIONS:

$ groovy -v
Groovy Version: 4.0.3 JVM: 1.8.0_271 Vendor: Oracle Corporation OS: Windows 10

$ gradle -v
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_271 (Oracle Corporation 25.271-b09)
OS:           Windows 10 10.0 amd64

BUILD FILE:
build.gradle:

plugins {
    id 'groovy'
}

group 'com.example.project'
version null

repositories {
    mavenCentral()
}

jar {
    archivesBaseName='theFinalJar'
    archiveVersion = null
}

dependencies {
// These are needed for Groovy 4.0.3 update, but fail cause "unable to resolve class"
   implementation group: 'org.apache.groovy', name: 'groovy', version: '4.0.3'
   implementation group: 'org.apache.groovy', name: 'groovy-sql', version: '4.0.3'
   implementation group: 'org.apache.groovy', name: 'groovy-dateutil', version: '4.0.3'

// Previous item, swapping to just this will work without issue.
//    implementation 'org.codehaus.groovy:groovy-all:2.4.4'

}

** Update **
To expand on the further weirdness of this, here is the code in question that is giving me issues. When I change the data type of “def” to “String” for “JobAuditMode”, the code compiles.

class jobParams {

    // Work Variables
    private def JobNumber
    private def JobLocation
    private def JobFileName
    private def JobAuditMode
//  private String JobAuditMode   // This works!

    // Default constructor
    JobsubParams() {
        this.JobNumber = ""
        this.JobLocation = ""
        this.JobFileName = ""
        this.JobAuditMode = ""
    }

Most probably not a Gradle issue, what should it be?
But you actually forgot to provide the actual error.

Yeah, thinking this might be more of a Groovy issue than anything. I’ll go back and review the code a bit more.

Here is the error I am receiving, which is totally explaining what the issue is:

D:\groovyJobs> gradle clean

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

D:\groovyJobs> gradle build

> Task :compileGroovy FAILED
startup failed:
D:\groovyJobs\src\main\groovy\com\example\project\JobsubParams.groovy: 13: unable to resolve class JobAuditMode
 @ line 13, column 5.
       private def JobAuditMode
       ^

So I’m confused why Gradle/Groovy ( I don’t know at this point) is considering my variable name as a class when it is defined as the “def” type.

It is a compile error coming from the Groovy compiler, so not a Gradle problem, no.