Reference SourceDirectorySet for include or exclude


(Stephen Byrne) #1

I would like to reference a SourceDirectorySet for another SourceSet - something like this:

sourceSets { // org.gadle.api.tasks.SourceSetContainer defined by java plugin
  appletA { // org.gradle.api.tasks.SourceSet named "appletA"
    java { // org.gradle.api.file.SourceDirectorySet from SourceSet.getJava()
      srcDir 'src'
      include 'net/sbyrne/appleta/**'
    }
  }
  main { // org.gradle.api.tasks.SourceSet named "main"
    java { // org.gradle.api.file.SourceDirectorySet from SourceSet.getJava()
      srcDir 'src'
      exclude sourceSets.appletA.java // MissingMethodException
      minus sourceSets.appletA.java // no error, does not exclude net.sbyrne.appleta
    }
  }
}

Is there some way to do this?

I realize my source layout is not ideal - I am trying not to change my existing layout for now.


(Luke Daley) #2
sourceSets { // org.gadle.api.tasks.SourceSetContainer defined by java plugin
  appletA { // org.gradle.api.tasks.SourceSet named "appletA"
    java { // org.gradle.api.file.SourceDirectorySet from SourceSet.getJava()
      srcDir 'src'
      include 'net/sbyrne/appleta/**'
    }
  }
  main { // org.gradle.api.tasks.SourceSet named "main"
    java { // org.gradle.api.file.SourceDirectorySet from SourceSet.getJava()
      srcDir 'src'
      exclude appletA.java.includes
    }
  }
}

That’s by far the simplest and most efficient.


(Stephen Byrne) #3

That runs without error, but does not exclude net/sbyrne/appleta/** from build/classes/main/.

EDIT: Oh wait, yes it does work, my mistake. Thanks Luke!