How to set one sourceSets compile dependency on a jar from second SourceSets

How to declare dependency between a sourceSet and jar task.

My gradle looks like this

sourceSet {
    main {
    }
    contrib {
    }
}
  task myJar(type: jar) {
   //This task builds jar from the sourceSets.main.output
}

Now the compilation of the contrib depends on the jar myJar . How can I declare this dependency ?

Also in the dependencies section I have contribCompile. Following line works

contribCompile sourceSets.main.output

but if I try to declare a dependency like this it fails

contribCompile myJar

Can someone please help me ?

I figured this out. The problem was there is no task named contrilCompile. The name of the task is compileContribJava . So any sourceSet you declare will have the task compile + <Your source, first letter Capitalized> + Java .