Custom sourceset compilation


(darthrub) #1

Hi, I am upgrading our gradle, from milestone-3 to the newest rc-3. In one of our projects we have a custom sourceset with just one java file (it is like a mock class). We are trying to use the compileMySourceJava, but it cannot be compiled with a lot of compilation errors (basically from the imports this class needs, so every instance to that imports are compilation errors). Previously gradlewise, this have been no problem, but now I have tried everything I found, but I am not able to compile that java file.

The idea for all this, is that for testing we need a class with the same name and in the same package, but when we want to make a jar package out of this project, we need this mock class.

we have something like this: sourceSets {

additionalClasses {

java{

compileClasspath += files(‘build/classes/main/’)

getOutput().setClassesDir(file(‘build/tmp/additionalClasses’))

}

} }

Thanks a lot for any help i can get.


(Luke Daley) #2

My guess is that ‘additionalClasses’ is being compiled before main. You could fix that with:

sourceSets {
   additionalClasses {
     java {
       compileClasspath += main.output
     }
   }
 }

That will cause the ‘main’ source set to be compile before ‘additionalClasses’. You shouldn’t need to set the ‘classesDir’ as you were.


(darthrub) #3

Thanks you for your answer, but does not seems to work for my case.

I see that the compileJava task is done before compileAdditionalClassesJava, and stills gives me a ton of compile fails.

The purpose for setting the classesDir, it is that when we call for gradle test, we don’t want the additionalClasses code. But when we packaging the application, we need that additionalClasses (with that set for classesDir).

If any more information about my problem is required, I would be glad to post it.

thank you again


(Luke Daley) #4

I don’t have enough info to go on.

Could you post your buildscript?