# How to share java class output from one subproject with another

**URL:** <https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228>\
**Category:** Help/Discuss\
**Created:** [December 11, 2023, 10:36pm UTC](https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228 "2023-12-11T22:36:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drone23](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@drone23](https://discuss.gradle.org/u/drone23)\
**Post date:** [December 11, 2023, 10:36pm UTC](https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228/1 "2023-12-11T22:36:56Z")

</div>

Hi,

I am trying to share a java class output from a subproject which is compiled from src/main to another subproject and access it in it’s src/test. I read the gradle docs ([Sharing outputs between projects](https://docs.gradle.org/current/userguide/cross_project_publications.html)) and can’t seem to get it working and it seems to only work for jars?

Can anyone help?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [December 12, 2023, 3:33pm UTC](https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228/2 "2023-12-12T15:33:05Z")

</div>

“Sharing outputs between projects” should not really apply here.  
You just declare a dependency from one subproject to the other and it will work.  
If something is not working as expected, you should probably share an [MCVE](https://stackoverflow.com/help/mcve) of what you try.

---

<div class="post-metadata">

**Author:** ![drone23](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@drone23](https://discuss.gradle.org/u/drone23)\
**Post date:** [December 12, 2023, 11:34pm UTC](https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228/3 "2023-12-12T23:34:04Z")

</div>

This works, but only in src/main. Not in src/test

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [December 13, 2023, 9:42am UTC](https://discuss.gradle.org/t/how-to-share-java-class-output-from-one-subproject-with-another/47228/4 "2023-12-13T09:42:47Z")

</div>

Still, can you share an MCVE to make it clear what you mean?
