Gradle, create and copy javadoc jars from multiple dependencies
<p>I have the following project structure:</p>

<ul>
<li>Project 1</li>
<li>Project 2 depends on Project 1</li>
<li>Project 3 depends on Project 1</li>
</ul>

<p>(there are also external dependencies)</p>

<p>I create source jars and javadoc jars with</p>

<pre><code>task sourcesJar(type: Jar) {
    destinationDir = file("./../../build/export/$project.name")
    classifier 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    destinationDir = file("./../../build/export/$project.name")
    classifier 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}
</code></pre>

<p>Now I need to create a folder which contains the jar file of a project and the jar files of all dependencies. My current version is</p>

<pre><code>task makeLibsDir(type: Copy, dependsOn: ['jar', 'sourcesJar', 'javadocJar']) {
   description 'Builds all relevant jar files to use this project as dependency and copies them to the libs folder'

   from jar // copying from jar configuration

   File outdir = file("./../../build/$project.name/libs/")
   outdir.mkdirs()
   into outdir

   into('/') {
          from configurations.runtime
  }
}
</code></pre>

<p>when I call project2:makeLibsDir I get a folder that contains</p>

<p>project1.jar project2.jar extDept1.jar ...</p>

<p>but there are two problems</p>

<ul>
<li>sources jar and javadoc jar for project1 are not build </li>
<li>sources jar and javadoch jar for project2 are build, but not copied to libs folder</li>
</ul>

<p>Any Idea how I can </p>

<ol>
<li>Ensure that all jars for all dependent projects are build</li>
<li>copy them to the final location</li>
</ol>

<p>Edit: Minimized Version of Full build.gradle</p>

<pre><code>buildDir = "../build/$project.name"

subprojects {
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

sourceSets {
       ....         
}

jar {
     destinationDir = file("./../../build/export/$project.name")
       destinationDir.mkdirs()
     baseName = project.name            
}


  task makeLibsDir(type: Copy, dependsOn: ['jar', 'sourcesJar', 'javadocJar']) {

      from jar

      File outdir = file("./../../build/$project.name/libs/")
      outdir.mkdirs()
      into outdir

      into('/') {
             from configurations.runtime
     }
   }

   task sourcesJar(type: Jar) {
          destinationDir = file("./../../build/export/$project.name")
       classifier 'sources'
       from sourceSets.main.allSource
   }

   task javadocJar(type: Jar, dependsOn: javadoc) {
      destinationDir = file("./../../build/export/$project.name")
      classifier 'javadoc'
      from javadoc.destinationDir
   }

   artifacts {
       archives sourcesJar
       archives javadocJar
   }

      project(':project1') {
        dependencies {
          ...
        }
      }

      project(':project2') {
        dependencies {
            ...
            compile project(':project1')  
        }
      }

      project(':project2') {
        dependencies {
              ...
              compile project(':project1')  
        }
      }
 }
</code></pre>