# Groovy version missmatch after adding dependency

**URL:** <https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985>\
**Category:** Help/Discuss\
**Created:** [November 14, 2023, 12:55pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985 "2023-11-14T12:55:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kushan](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@Kushan](https://discuss.gradle.org/u/Kushan)\
**Post date:** [November 14, 2023, 12:55pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/1 "2023-11-14T12:55:09Z")

</div>

I have two java spring boot projects. The versions are mentioned below.

# Project 1

```gradle
Java - 21
Gradle - 8.4
Groovy - 3.0.17
Spock - 2.4-M1-groovy-3.0

```

# Project 2

```gradle
Java - 8
Gradle - 6.7
Groovy - 2.5.13
Spock - 1.1-groovy-2.4

```

I have used the following options in project 1 to make its dependency Java 8 compatible.

```gradle
compileJava {
    options.release = 8
}

java {

    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }

    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_1_8
}

```

Then I imported the project 1 dependency into project 2 and it gives following error. Seeking for a solution for this.  
`org.spockframework.util.IncompatibleGroovyVersionException: The Spock JUnit runner cannot execute because Spock 1.1.0-groovy-2.4 is not compatible with Groovy 3.0.17.`

---

<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:** [November 14, 2023, 1:21pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/2 "2023-11-14T13:21:10Z")

</div>

Well, as the error says.  
Where you get this error you have Groovy 3 with a Spock version that is for Groovy 2.4 and this is not compatible.  
If the message is a red herring, you need to provide more details, optimally a build `--scan`.

---

<div class="post-metadata">

**Author:** ![Kushan](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@Kushan](https://discuss.gradle.org/u/Kushan)\
**Post date:** [November 14, 2023, 1:35pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/3 "2023-11-14T13:35:33Z")

</div>

Its failing when tests are executed. The error is `org.spockframework.util.IncompatibleGroovyVersionException at VersionChecker.java:22`.  
Can’t we create a jar file without groovy dependencies? I want to add my project 1 dependency into project 2 without changing any groovy or other dependencies in project 2.

---

<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:** [November 14, 2023, 1:40pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/4 "2023-11-14T13:40:09Z")

</div>

Can you provide an [MCVE](https://stackoverflow.com/help/mcve)?  
Having Spock as test framework in 2 should not at all influence 1 even with a dependency on 2.  
So it is most probably something you configured. somehow.  
But it is impossible to guess where the problem is, from the information you provided.

---

<div class="post-metadata">

**Author:** ![Kushan](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@Kushan](https://discuss.gradle.org/u/Kushan)\
**Post date:** [November 15, 2023, 4:19am UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/5 "2023-11-15T04:19:40Z")

</div>

Here is some result from build --scan. I can see groovy 3.0.17 libs under detachedConfiguration1. I think this causing the issue.  
 ![image](https://global.discourse-cdn.com/gradle/original/2X/2/231a2fb36bfa167c72ea3005d595be3245cdbfa4.png)

---

<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:** [November 15, 2023, 11:27am UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/6 "2023-11-15T11:27:39Z")

</div>

I don’t know where that detached configuration is from, but 3.0.17 is ok in 1, isn’t it?  
The question is, why Spock 1.1.0-groovy-2.4 ends up in the test compile classpath of 1.

---

<div class="post-metadata">

**Author:** ![Kushan](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@Kushan](https://discuss.gradle.org/u/Kushan)\
**Post date:** [November 15, 2023, 12:01pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/7 "2023-11-15T12:01:20Z")

</div>

In project 1, it has added groovy libraries like this(library root). Also when I try to upgrade groovy 3.0.17 to 3.0.19 it gives me `Module [groovy-datetime is loaded in version 3.0.17 and you are trying to load version 3.0.19` error. Seems like gradle 8.4 has groovy 3.0.17 inbuild and it doesn’t allow me to change groovy version into a different version as it already imported some modules from groovy 3.0.17.  
 ![image](https://global.discourse-cdn.com/gradle/original/2X/4/4dff4d5405ef7f539f6048cd1f9fc6178343fa20.png)

---

<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:** [November 15, 2023, 1:12pm UTC](https://discuss.gradle.org/t/groovy-version-missmatch-after-adding-dependency/46985/8 "2023-11-15T13:12:41Z")

</div>

Whatever Gradle has built-in (yes it is 3.0.17) should be irrelevant unless you build a Gradle plugin.

The normal production classpath or also the test classpath are unaffected by that unless you explicitly say you want that shipped version.

But again, you said your problem is that Spock 1.1-groovy-2.4 is in the test compile classpath and that is of course not compatible to Groovy 3 and that Groovy 3 is indeed what should be present in 1.

Anyway, I don’t think I can give any more meaningful advice as you neither provided the requested MCVE, nor the build scan, and from the little and contradictory information you gave it is impossible for me to come up with any suggestion.
