Generated sources end up in the built jar file

I used the method to generate sources shown here:

But the generated sources are packed in to the jar artifact together with the classes. Is this by design? How can I avoid it? I guess I can exclude them, but is there a neater way?

This sample snippet in the userguide is actually not demoing how to deal with generated sources. It is about dealing with generated resources. By design resources are packaged with the jar.

Well, it wasn’t far fetched since it is a feature on SourceSets. Is there a better way to handle generated sources?

By the way, I solved my problem by naming the source set something other than main.

I found a strange problem though. Using this method and trying to exclude the main source set from eclipse, it seems that the generated dir follows with the main sourceset even though I use a different name:

sourceSets {
  generatedMainSourceSet {
    //let's register an output folder on the main SourceSet:
    output.dir("$buildDir/generated-src/main", builtBy: 'wsdl2java')
    //it is now a part of the 'main' classpath and will be a part of the jar
  main {
    java {
      srcDirs = []

eclipse {
    classpath {
        sourceSets -= [sourceSets.main]

If I remove the main sourecset from eclipse, both src/main/java and build/generated-src/main are removed, if I add it, both are added. A bug?