Gradle upgrade to 6.7 causing spotbug issues

I’m upgrading to Gradle 6.7.

I followed https://github.com/spotbugs/spotbugs-gradle-plugin and updated Gradle to pick 6.7. That gave me some error about spotbugs so I updated spotbugs version in buildScript as following

    buildscript {
        dependencies {
           .
           .
           classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.6.0'
           .
           .
        }
    }

and as suggested I added

dependencies {
    spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
    spotbugs 'com.github.spotbugs:spotbugs:4.0.0'
}

and updated

 spotbugs {
    toolVersion = "4.1.4"
 }

After this I started getting following two errors

1. A problem occurred evaluating script.There’s an extension registered with name ‘sourceSets’. You should not reassign it via a property setter.

In my .gradle file sourceSets are being set as

spotbugs {
    toolVersion = "4.1.4"
    sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest]
}
  1. the second error is
Caused by: org.gradle.api.tasks.TaskInstantiationException: Could not create task of type 'SpotBugsTask'.
        at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:97)
        at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:84)
        at org.gradle.util.GUtil.uncheckedCall(GUtil.java:442)
        at org.gradle.api.internal.AbstractTask.injectIntoNewInstance(AbstractTask.java:201)
        at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:84)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.create(AnnotationProcessingTaskFactory.java:48)
        at org.gradle.api.internal.tasks.DefaultTaskContainer.createTask(DefaultTaskContainer.java:326)
        at org.gradle.api.internal.tasks.DefaultTaskContainer.access$200(DefaultTaskContainer.java:77)
        at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreatingProvider.createDomainObject(DefaultTaskContainer.java:701)
        at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreatingProvider.createDomainObject(DefaultTaskContainer.java:658)
        at org.gradle.api.internal.DefaultNamedDomainObjectCollection$AbstractDomainObjectCreatingProvider.tryCreate(DefaultNamedDomainObjectCollection.java:941)
        ... 184 more
Caused by: java.lang.NoSuchMethodError: 'java.lang.Object org.gradle.util.DeprecationLogger.whileDisabled(org.gradle.internal.Factory)'
        at com.github.spotbugs.SpotBugsTask.createReports(SpotBugsTask.java:102)
        at com.github.spotbugs.SpotBugsTask.<init>(SpotBugsTask.java:98)
        at com.github.spotbugs.SpotBugsTask_Decorated.<init>(Unknown Source)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:1969)
        at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:468)
        at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
        at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:50)
        at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:90)
        ... 194 more

Any help in fixing these errors?