How to setup dependencies in a multi module Android Gradle project with interdependencies?
<h2>The Question</h2>

<p>How do I setup the dependencies of the modules in an Android Gradle project, where the modules have dependencies on each other, such that I can deploy a build of a new snapshot or release version of all modules in one go?</p>

<h2>Project Setup</h2>

<p>I have a project that consists of 2 modules: lib-core and lib-help, with lib-help depending on lib-core. I want to publish lib-core and lib-help seperately to Maven Central, such that the pom file of lib-help specifies the dependency on lib-core with the correct version.</p>

<p>The project is structured as follows:</p>

<pre><code>/my-project-name
|
|--/lib-core
|  |-- build.gradle
|  |-- gradle.properties
|
|--/lib-help
|  |-- build.gradle
|  |-- gradle.properties
|
|-- build.gradle
|-- gradle.properties
|-- settings.gradle
|-- gradle-mvn-push.gradle
</code></pre>

<p>The project configuration files are as follows, showing only the relevant parts (by my judgement):</p>

<p><strong>settings.gradle</strong>:</p>

<pre><code>include ':lib-core', ':lib-help'
</code></pre>

<p><strong>gradle.properties</strong>:</p>

<pre><code>GROUP=com.company
VERSION=5.0.0-SNAPSHOT
</code></pre>

<p><strong>gradle-mvn-push.gradle</strong>:</p>

<pre><code>apply plugin: 'maven'

afterEvaluate { project -&gt;
    uploadArchives {
        repositories {
            mavenDeployer {
                // GROUP is defined in &lt;root&gt;/gradle.properties
                pom.groupId = GROUP
                // ARTIFACT is defined in &lt;root&gt;/&lt;module&gt;/gradle.properties
                pom.artifactId = ARTIFACT
                // VERSION is defined in &lt;root&gt;/gradle.properties
                pom.version = VERSION
            }
        }
    }
}

// Contains a lot more to fill in other meta-data like project name,
// developer name, github url, javadoc, signing of the artifacts, etc, etc..
</code></pre>

<p><strong>lib-core/gradle.properties</strong>:</p>

<pre><code>ARTIFACT=my-lib-core
</code></pre>

<p><strong>lib-core/build.gradle</strong>:</p>

<pre><code>apply plugin: 'com.android.library'

// Contains more code to configure the android stuff, not relevant for this question

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

apply from: rootProject.file('gradle-mvn-push.gradle')
</code></pre>

<p><strong>lib-help/gradle.properties</strong>:</p>

<pre><code>ARTIFACT=my-lib-help
</code></pre>

<p><strong>lib-help/build.gradle</strong>:</p>

<pre><code>apply plugin: 'com.android.library'

// Contains more code to configure the android stuff, not relevant for this question

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':lib-core')
}

apply from: rootProject.file('gradle-mvn-push.gradle')
</code></pre>

<h2>The Problem</h2>

<p>When I run <code>gradlew clean :lib-core:uploadArchives :lib-help:uploadArchives</code>, everything compiles nicely and uploads are being pushed to the correct repository. In the Nexus Repository Manager I can see the artifacts for both modules with the correct name, version, signing, etc., but the dependency of lib-help on lib-core in the generated pom.xml is wrong. It uses the project name as groupId, the module name as the artifactId and an unspecified version name:</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;my-project-name&lt;/groupId&gt;
    &lt;artifactId&gt;lib-core&lt;/artifactId&gt;
    &lt;version&gt;unspecified&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
</code></pre>

<p>Consequently, projects using lib-help as a dependency can't resolve the lib-core dependency. The correct values that should have been in lib-help's pom.xml are groupId=com.company, artifactId=my-lib-core and version=5.0.0-SNAPSHOT.</p>

<p>To fix this, I thought I'd use a maven dependency in lib-help, instead of a module dependency, like this:</p>

<pre><code>dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.company:my-lib-core:' + VERSION
}
</code></pre>

<p>Naturally, this version does not exist before the uploadArchives command of lib-core has been executed, but gradle wants to resolve the dependencies of all modules before starting execution of any of the given commands. Thus, it can't resolve this dependency and quits with an error while configuring the gradle projects. Now, I can work around this by temporarily setting the dependency of lib-help to <code>project(':lib-core')</code>, then release lib-core, then adjust the dependency of lib-help to <code>'com.company:my-lib-core:5.0.0-SNAPSHOT'</code>, then release lib-help, but that just doesn't seem the right way. It invites human mistakes (what if I accidentally increase the version number between the to uploadArchives commands?) and it takes several manual, strictly ordered steps.</p>

<h2>The Question (reprise)</h2>

<p>How do I setup the dependencies of the modules in an Android Gradle project, where the modules have dependencies on each other, such that I can deploy a build of a new snapshot or release version of all modules in one go? (e.g., but not necessarily, with the command <code>gradlew clean :lib-core:uploadArchives :lib-help:uploadArchives</code>)</p>