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

**URL:** <https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270>\
**Category:** Old Forum Archive\
**Created:** [March 24, 2014, 9:01am UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270 "2014-03-24T09:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sonja\_Bock](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Sonja\_Bock](https://discuss.gradle.org/u/Sonja_Bock)\
**Post date:** [March 24, 2014, 9:01am UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270/1 "2014-03-24T09:01:00Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Radim\_Kubacki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/radim_kubacki/32/1032_2.png) [@Radim\_Kubacki](https://discuss.gradle.org/u/Radim_Kubacki)\
**Post date:** [March 24, 2014, 3:45pm UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270/2 "2014-03-24T15:45:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sonja\_Bock](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Sonja\_Bock](https://discuss.gradle.org/u/Sonja_Bock)\
**Post date:** [March 31, 2014, 2:14pm UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270/3 "2014-03-31T14:14:00Z")

</div>

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

```gradle
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](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?

---

<div class="post-metadata">

**Author:** ![Radim\_Kubacki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/radim_kubacki/32/1032_2.png) [@Radim\_Kubacki](https://discuss.gradle.org/u/Radim_Kubacki)\
**Post date:** [April 1, 2014, 9:51am UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270/4 "2014-04-01T09:51:00Z")

</div>

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](http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html)

---

<div class="post-metadata">

**Author:** ![Sonja\_Bock](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Sonja\_Bock](https://discuss.gradle.org/u/Sonja_Bock)\
**Post date:** [April 2, 2014, 11:45am UTC](https://discuss.gradle.org/t/how-to-handle-split-to-api-and-impl-in-src-generated-java-and-use-same-classpath-as-src-main-java-files/6270/5 "2014-04-02T11:45:00Z")

</div>

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.
