I do not know how to add static methods to a class using mixins, but you can add static methods to a class through the metaClass.static property. Here's an example that adds a static fqn() method that prints the full class name
Class.metaClass.static.fqn = { delegate.name } assert String.fqn() == "java.lang.String"
If you want to add fqn() (and other static methods) to several classes (e.g. List, File, Scanner), you can do something like
def staticMethods = [fqn: {delegate.name}, fqnUpper: {delegate.name.toUpperCase()}] [List, File, Scanner].each { clazz -> staticMethods.each{methodName, methodImpl -> clazz.metaClass.static[methodName] = methodImpl } }
source share