subprojects {
    apply plugin: 'java'
    apply plugin: 'ivy-publish'

    repositories {
        mavenCentral()
    }

    publishing {
        repositories {
            ivy {
                url "${rootProject.buildDir}/repo" // change to point to your repo, e.g. http://my.org/repo
            }
        }
    }
}

project(":project1") {
    dependencies {
       compile 'junit:junit:4.12'
    }


    publishing {
        publications {
            ivy(IvyPublication) {
                organisation 'org.gradle.sample'
                module 'project1-sample'
                revision '1.1'
                descriptor.status = 'milestone'
                descriptor.branch = 'testing'
                descriptor.extraInfo 'http://my.namespace', 'myElement', 'Some value'

                from components.java
            }
        }
    }
}

project(":project2") {
    task apiJar(type: Jar) {
        baseName "publishing-api"
        from sourceSets.main.output
        exclude '**/impl/**'
    }

    dependencies {
       compile 'commons-collections:commons-collections:3.2.2', project(':project1')
    }

    publishing {
        publications {
            impl(IvyPublication) {
                organisation 'org.gradle.sample.impl'
                module 'project2-impl'
                revision '2.3'

                from components.java
            }
            api(IvyPublication) {
                configurations {
                    it.default {
                        extend "runtime"
                    }
                    runtime {}
                }
                artifact(apiJar) {
                    conf "runtime"
                }

                organisation 'org.gradle.sample'
                module 'project2-api'
                revision '2'
            }
        }
    }
}
