title: How to resolve circular dependency in Gradle
body: <p>I am migrating a Java project from Ant to Gradle. I think the best solution is to use Gradle's multi-project support, but I cannot find a way to get rid of a circular dependency.</p>
  
  <p>The original project was setup to have this layout:</p>
  
  <pre><code>- project/
    - common/
    - product-a/
    - product-b/
  </code></pre>
  
  <p>The relationship between <code>common</code>, <code>product-a</code>, and <code>product-b</code> is tricky. The <code>common</code> depends on <code>product-a</code> or <code>product-b</code>, depending on a configuration file. Likewise, <code>product-a</code> and <code>product-b</code> depend on <code>common</code>, regardless of the configuration property. <code>product-a</code> and <code>product-b</code> will never be built at the same time.</p>
  
  <p>I thought a quick solution would be to use something like this in the <code>project/build.gradle</code>:</p>
  
  <pre><code>project(':product-a') {
      dependencies {
          compile project(':common')
      }
  }
  
  project(':product-b') {
      dependencies {
          compile project(':common')
      }
  }
  </code></pre>
  
  <p>Next, I thought about getting a way to get this closer to working for just <code>product-a</code>. That led me to this:</p>
  
  <pre><code>project(':common') {
      dependencies {
          compile project(':product-a')
      }
  }
  </code></pre>
  
  <p>This will throw an exception for having a circular dependency.</p>
  
  <p>I've considered refactoring <code>product-a</code> and <code>product-b</code> by setting up interfaces of the classes expected by <code>common</code> and <code>product-a</code>/<code>product-b</code> or by using polymorphism, but before I move forward with either of those, is there a better way to accomplish this with Gradle? I'm not ready to get rid of this technical debt yet.</p>