Adding Groovy function which imports from java.nio.file.Files

I’ve created a Groovy function that needs to use some standard JRE stuff. At first I had it in my root build.gradle, but I couldn’t import the needed package. So I created a groovy file in buildSrc which can import java.nio.file.Files and compiles correctly. However now my sub-projects can’t refer to the method in this Groovy file.

What is the right way to define a method like this and make it available to all sub-projects?

import java.nio.file.Files

    void bundleApks(project, files) {
        println "project name: ${project.name}"
    
        files.each { f->
            println "file name: ${f.path}"
            def dest = f.path.contains('debug') ? 'debug' : 'release'
            def destDir = file("$bundleDir/$dest")
            Files.copy(f.path, destDir.path)
        }
    }

I am not going to answer your question, but rather going to point out that you that the above is already supported in Gradle.

ext {
  bundleApks = { someFiles ->
    def files = project.files(someFiles)  
    project.copy {
      from files.filter { it.contains('debug') } 
      into "${bundleDir}/debug"  
    }
    project.copy {
      from files.filter { !it.contains('debug') }
      into "${bundleDir}'/release"
    }
 }
}

If your functions are as simple as those above, you can just place them in another gradle script and do
apply from: '/path/to/my/functions.gradle'