How to create a Java task of type Jar that implements the from method of CopSpec?

I have a task in the build.gradle file as follows:
task jar(type: Jar, overwrite: true) {
And I am creating a Java class that extends DefaultTask and that should do exactly this but in Java as follows:
public class JarTask extends DefaultTask {
public void jar() { }

How can I implement the from method?