# Publishing a multi-project build as a library

**URL:** <https://discuss.gradle.org/t/publishing-a-multi-project-build-as-a-library/15410>\
**Category:** Help/Discuss\
**Created:** [March 24, 2016, 2:43pm UTC](https://discuss.gradle.org/t/publishing-a-multi-project-build-as-a-library/15410 "2016-03-24T14:43:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick\_smith](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@nick\_smith](https://discuss.gradle.org/u/nick_smith)\
**Post date:** [March 24, 2016, 2:43pm UTC](https://discuss.gradle.org/t/publishing-a-multi-project-build-as-a-library/15410/1 "2016-03-24T14:43:27Z")

</div>

What we want to do is publish a multi module java project as a library.

We have dependencies between modules (these are declared as dependencies in a build.gradle file) and we seem to be successfully publishing a jar file.  
However, when we reference this jar as a dependency, gradle moans about not not being able to ‘find’ the subprojects.

So for a structure like this:

```
water/
  build.gradle
  settings.gradle
  bluewhale/
  krill/ 

```

`water` is just a gradle wrapper for `bluewhale` where some code lives.  
`krill` is a collection of useful methods that `bluewhale` depends on.  
Especially if we were to add `greenwhale` at some point in the future it makes sense for `krill` to be a separate (java) module.

In the **settings.gradle** file I’ll include both of the subprojects  
`include 'bluewhale', 'krill'`

And the **build.gradle** (roughly)

```
apply plugin: 'java'
<.......etc.......>
     
project(':bluewhale') {
   dependencies {
      compile project(':krill')
   }

project(':krill') {
   dependencies {
      compile 'some:dep:1.0'
   }

```

Now, I want to bundle this up as a jar and share it with the world.  
Really, I only want to expose `bluewhale` but I don’t care if I have to publish it as `water`

Having successfully published `water.jar` when I reference it in another project gradle moans:

`> Could not find water:krill:unspecified.`

It seems like the jar is holding on to some reference of a gradle project dependency.

Surely I don’t have to publish every single module separately?  
Our project structure has close to 20 modules which we’d probably want to split into 2/3, not 20…  
Do we have to put everything into 1 monolith module to publish as a library?

I feel like this is something gradle can handle but I’m baffled as to what I’m doing wrong.  
Any pointers would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![mattjohnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mattjohnson/32/4815_2.png) [@mattjohnson](https://discuss.gradle.org/u/mattjohnson)\
**Post date:** [March 26, 2016, 2:29am UTC](https://discuss.gradle.org/t/publishing-a-multi-project-build-as-a-library/15410/2 "2016-03-26T02:29:54Z")

</div>

Check out the shadow plugin: [https://github.com/johnrengelman/shadow](https://github.com/johnrengelman/shadow)

It allows you to package dependencies into a single JAR.
