Include generated Jar and aar as a dependency in Android project
<p>I have a AndroidStudioSupport Project which has modules. 
1. module 1 takes care of Android UI part
2. module 2 is a library project which generates .aar file
3. module 3 is a java project which generates jar file</p>

<p>Now I want to build the project in a way that
1. First build jar project 
2. Then copy generated jar into libs of library project as a dependency
3. Then build aar file 
4. Then copy generated aar into libs of UI project as a dependency
5. Finally generate .apk file </p>

<p>Please suggest me what changes do I have to do in my gradle files</p>

<p>jar project gradle file</p>

<pre><code>apply plugin: 'java'
sourceSets {
    main.java.srcDirs = ['src/main/java']
    main.resources.srcDirs = ['src/main/java']
    test.java.srcDirs = ['tests/java']
    test.resources.srcDirs = ['tests/resources']
}

jar {
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it)}
    }
}
</code></pre>

<p>library project gradle file</p>

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

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

task copyToLib(type: Copy) {
    from configurations.compile
    into 'libs'
}

build.dependsOn(copyToLib)

android {
    publishNonDefault true
    compileSdkVersion 21
    buildToolsVersion '23.0.2'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/java']
            aidl.srcDirs = ['src/main/java']
            renderscript.srcDirs = ['src/main/java']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('test')
    }
    buildTypes {
        debug {
            jniDebuggable true
        }
    }
}
</code></pre>

<p>This current implementation doesn't include jar from my java project</p>