Now to the problem. I have a class A in “src” which have a dependency on a class B in “model”. Therefore the classes in “model” must be available before building the classes in “src”.
Is it possible to introduce a build order for source folders in a project?
I have tried to swap the above folders in the sourceSets and I have also tried to use “dependsOn” when bulding the extra jar but it does not solve the problem. Any suggestions?
EDIT:
Adding this:
sourceSets.main.java.srcDirs 'model'
fixes the compile error but as a result the default jar also contains the model code which I don’t want.
Why do you write “//OR” in the above snippet? Currently I need both and it appears to work.
You shouldn’t need both, as they are variations of the same thing (get the model classes on the compile class path of the main code).
but I get: “Circular dependency between tasks. Cycle includes [task ‘:compileTestJava’, task ‘:testJar’].” If I remove “compile testJar.outputs.files” and pass the task testJar on the commandline it works.
You don’t need that line, because you don’t want your test classes on the compile class path of your main code. It wouldn’t even work because it contradicts having the main classes on the compile class path of the test code, which is something that you do want (and is already set up for you by the Java plugin).
Just to be clear, ‘dependencies.compile’ means the compile dependencies of the main code. There’s also ‘dependencies.testCompile’ and ‘dependencies.modelCompile’ (and likewise for ‘runtime’).