Hi,
I’m trying to get a generated class on the compile classpath by following the SourceSetOutput DSL example:
sourceSets {
main {
output.dir(generatedResources, builtBy: 'compileJs')
}
}
The compileJs task uses Rhino to compile javascript into a class file before the java compilation starts, but the java compilation fails because the generatedResources dir is not in the compile classpath. Is this expected?
As workaround I deleted the sourceSets but added the directory explicitly to the classpath:
dependencies {
compile files(generatedResources) { builtBy 'compileJs' }
}
But then I also had to add the generatedResources dir manually to the jar.
The sourceSets solution would look better if it worked 
Grtz, Ivo
Hi Ivo,
I think you have two distinct problems here
- You need your Rhino generated classes to be included in your Jar.
The Jar will include the output of the main SourceSet. So as you found, you should be able to achieve this by considering your Rhino generated classes like special resources and adding them to the SourceSet output.
However, ALSO:
- You need the Rhino generated classes on the classpath when you compile your java classes.
The javaCompile task takes INPUT source from the SourceSet and generates classes that it places in the SourceSet OUPUT. It doesn’t really make sense to expect it to treat classes already in the output as part of its input. Instead you need to declare a compile dependency so that gradle knows those classes are needed to compile against.
So long story short, you need to do both things to get the effect you want
sourceSets {
main {
output.dir(generatedResources)
}
}
dependencies {
compile files(generatedResources) { builtBy 'compileJs' }
}
This was exactly what I was looking for. It does the same thing as what I had before, but now the intent is better communicated by the code 
Tnx