How do you configure advanced java source sets?

The java plugin documentation is very detailed but does show any advanced examples:

  1. Please explain how to create a source set that filters out specific set of files inside of a source dir?

What is wrong with this code?

sourceSets {
    main {
        java {
            source fileTree( dir: 'src')
        }
    }
  1. Please explain how to use a custom source set name other than main or test. How do you tell gradle to compile/jar the custom source set?

ad 1. Sources are always directories, not individual files. You can declare ‘include’ and ‘exclude’ filters on the ‘SourceDirectorySet’ level (e.g. ‘sourceSets.main.java.exclude “**/*Test.java”’). You cannot currently have different filters per directory.

ad 2. With the ‘java(-base)’ plugin, you automatically get a compile task for each source set. The Jar task you’ll have to declare yourself. See the ‘withIntegTests’ sample in the full Gradle distribution for how to configure a custom source set.