Recently trying to upgrade from 5 to 8 version. Build failing at Def methods

Groovy DEF methods doesn’t work in latest gradle 8.1.1 ?

def copyPolicyExportJarsToJDK() {
                def doneFile = file(MARKER_DIR.absolutePath + "/JCE_POLICIES_COPY.done")
                if (!doneFile.exists()) {
                        if(hasProperty('JCE_POLICY_ZIP') && JCE_POLICY_ZIP) {
                                def zipFile = file(JCE_POLICY_ZIP)
                                copy {
                                        from zipTree(zipFile).files
                                        into JAVA_HOME + File.separator + "jre" + File.separator + "lib" + File.separator + "security"
                                        include '/*.jar'
                                }
                                doneFile.createNewFile()
                        } else {
                                println "JCE_POLICY_ZIP variable not set. Will not attempt to copy the policy jars to JDK"
                        }
                }
        }
Build failed:
> Could not find method copyPolicyExportJarsToJDK() for arguments [build_e67cth4ldo02nu8qt7t68alvl$_run_closure39@16c1c268] on root project 'otest' of type org.gradle.api.Project.

The error says that you try to call that method with an argument, but your method does not take any arguments.
In Gradle 5 the built-in Groovy version was 2.5.4, in Gradle 8 it is 3.0.15, so it could of course be that there was some backwards incompatible change in how Groovy parses and handles your build scripts.
But hard to guess without seeing the whole build.

Generally, such functions should still work just fine.

Thanks for the info. Will cross check again

Resolved the issue. This code is defined in another task. Removed inside the task, worked. Thanks