title: Gradle - can I include task's output in project dependencies
body: <p>I have a task that generates java sources and a set of jars from these sources (say, project <code>a</code>). I would like to export these jars to dependent projects (say, project <code>b</code>). So here's roughly what I have right now:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>//a.gradle
  
  configurations{
    generatedJars
  }
  
  task generateJars(type: JavaExec) { 
    //generate jars ... 
  
    outputs.files += //append generated jars here
  } 
  
  dependencies{
    generatedJars generateJars.outputs.files
  }
  
  
  //b.gradle
  
  dependencies{
    project(path: ':a', configuration: 'generatedJars')
  }
  </code></pre>
  
  <p>It works OK, except that adding <code>generateJars.outputs.files</code> as a dependency does not tell gradle that it has to run <code>generateJars</code> task when there are no jars generated yet. I have tried adding the task itself as a dependency hoping that it would work in the same way as it does when you add a jar/zip task to an artifact configuration (e.g. <code>artifacts{ myJarTask }</code>), but it throws an error telling me that I cannot do that. Of course I can inject the <code>generateJars</code> task somewhere in the build process before <code>:b</code> starts evaluating, but that's clumsy and brittle, so I would like to avoid it.</p>
  
  <p>I feel like I should be adding the generated jars to <code>artifacts{ ... }</code> of the project, but I am not sure how to make them then visible to dependent projects. Is there a better way of achieving this?</p>
  
  <p>Dependent projects (project <code>b</code>) will need to do setup IntelliJ IDEA module classpath to point to project <code>a</code>'s generated jars. Something rather like this (pseudo-code):</p>
  
  <pre class="lang-groovy prettyprint-override"><code>//b.gradle
  
  idea{
    module{
      scopes.COMPILE.plus += project(path: ':a', configuration: 'generatedJars').files
    }
  }
  </code></pre>
  
  <p>So far I have tried simply adding a project dependecy on <code>:a</code>'s <code>generatedJars</code> in <code>:b</code>, but Idea plugin simply adds module <code>:a</code> as a module-dependency and assumes that it exports its generated jars (which is probably a correct assumption), therefore not adding the generated jars to <code>:b</code>'s classpath.</p>
  
  <p>Any help would be greatly appreciated!</p>