# Gradle compile issues migrating from Groovy 2.4.4 to 4.0.3

**URL:** <https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347>\
**Category:** Help/Discuss\
**Created:** [July 15, 2022, 8:46pm UTC](https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347 "2022-07-15T20:46:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MexicanNinja](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@MexicanNinja](https://discuss.gradle.org/u/MexicanNinja)\
**Post date:** [July 15, 2022, 8:46pm UTC](https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347/1 "2022-07-15T20:46:13Z")

</div>

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:

```gradle
$ 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:

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

```gradle
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 = ""
    }

```

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 16, 2022, 11:40pm UTC](https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347/2 "2022-07-16T23:40:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MexicanNinja](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@MexicanNinja](https://discuss.gradle.org/u/MexicanNinja)\
**Post date:** [July 18, 2022, 11:17pm UTC](https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347/3 "2022-07-18T23:17:00Z")

</div>

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:

```gradle
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.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 19, 2022, 12:35am UTC](https://discuss.gradle.org/t/gradle-compile-issues-migrating-from-groovy-2-4-4-to-4-0-3/43347/4 "2022-07-19T00:35:50Z")

</div>

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