ben-manes / gradle-versions-plugin

Gradle plugin to discover dependency updates
Apache License 2.0
3.82k stars 199 forks source link

Getting java.lang.NoClassDefFoundError: groovy/xml/XmlSlurper when I try to execute dependencyUpdates task #778

Closed losmurfs closed 1 year ago

losmurfs commented 1 year ago

stacktrace.txt

Get groovy/xml/XmlSlurper error when I execute the following in my gradle project: gradle dependencyUpdates

Tried adding groovy like this: ~/.gradle/init.d/add-versions-plugin.gradle

initscript {
  repositories {
    mavenCentral()
    gradlePluginPortal()
  }

  dependencies {
    classpath 'com.github.ben-manes:gradle-versions-plugin:0.46.0'
    classpath 'org.codehaus.groovy:groovy-all:3.0.17'
  }
}

def isNonStable = { String version ->
  def unstableKeyword = ['alpha','beta','rc','cr','m','-b'].any { version.toLowerCase().contains(it) }
  return unstableKeyword
}

allprojects {
  apply plugin: groovy
  apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin
  tasks.named("dependencyUpdates").configure {
    dependencyUpdates.rejectVersionIf {
      (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) ||
      (it.candidate.module == 'commons-io' && it.candidate.version.startsWith('2003')) ||
      (it.candidate.module == 'commons-net' && it.candidate.version.startsWith('2003')) ||
      (it.candidate.module == 'commons-discovery' && it.candidate.version.startsWith('2004')) ||
      (it.candidate.module == 'commons-discovery' && it.candidate.version.startsWith('2003'))
    }
  }
}
ben-manes commented 1 year ago

I believe that is a Gradle version issue due to their Groovy upgrade. In Gradle 7.x+ you can use v43 or above, else an older version. For some reason our tests don't fail even though we run against Gradle 5.0. The older version of the plugin uses groovy.util.XmlSlurper which Groovy deprecated and removed.

losmurfs commented 1 year ago

I believe that is a Gradle version issue due to their Groovy upgrade. In Gradle 7.x+ you can use v43 or above, else an older version. For some reason our tests don't fail even though we run against Gradle 5.0. The older version of the plugin uses groovy.util.XmlSlurper which Groovy deprecated and removed.

So what is my solution?

ben-manes commented 1 year ago

If you are on Gradle 6.x or below, use the plugin version v42. The plugin releases are primarily compatibility fixes with Gradle's changes, so you shouldn't have a problem with an older version. Once you are on Gradle 7.x+ then you can switch to the latest release.