How to handle split to api and impl in src/generated/java and use same classpath as src/main/java files?

I use two folders with java files in one project: - src/main/java - src/generated/java with api and impl packages

My result is to get separate jar files for each api and impl package of src/generated/java and one more which includes the output of src/main/java.

But i get problems because there exist dependencies from src/main/java to src/generated/java and backwards! Inside the eclipse project (without using gradle) there are no problems with the dependencies because all files are inside the same project.

I tried the following solution and it is nearly great, but with the dependencies in both directions i get errors: https://github.com/gradle/gradle/commit/146d0c5919e50d54eec8081079ef3256779e3a5e

How can i use separate source sets (api, impl, main) which know about the files of the other source sets?

Because i’m nearly new i would be grateful for an example.

Indeed, circular dependencies are a problem. In what order do you expect your sources will be built? You will need to break that circle.

Alternatively you can keep one sourceSet add both directories to it. You can also add tasks to build those JARs that you have mentioned though I do not see why you want to do it if they depend on each other.

Now i work with the original main/java sourceSet and i added the src/generated/java path to it:

sourceSets {
      main {
         java {
            srcDir 'src/generated/java'
         }
      }
   }

Furthermore i created a new task apiJar which is described in example 65.5 in chapter http://www.gradle.org/docs/current/userguide/publishing_maven.html

It works fine this way.

Now i want to use this custom task in a multi project environment for more subprojects. What is your idea to handle this without getting an error that a task with this name does already exist?

I do not understand what’s the problem there. Just use the same task with the same name in your projects. If you are in doubt how projects and tasks work I would recommend you to look at userguide at http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html

I found a solution to handle my custom jar files to spilt api and impl files. With one sourceSet all dependencies are resolved correctly and all works fine.

Thanks for your help.