buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.apache.commons:commons-math3:3.6.1'
    }

}

configurations {
   spi
}

// tag::dependencies[]
// tag::project-dependencies[]
dependencies {
    compile project(':shared')
// end::project-dependencies[]
// end::dependencies[]
    compile module("org.apache.commons:commons-lang3:3.7") {
        dependency("commons-io:commons-io:2.6")
    }
// tag::dependencies[]
// tag::project-dependencies[]
}
// end::dependencies[]
// end::project-dependencies[]

// Just a smoke test that using this option does not lead to any exception
compileJava.options.compilerArgs = ['-Xlint:unchecked']

task spiJar(type: Jar) {
    appendix = 'spi'
    from sourceSets.main.output
    include 'org/gradle/api/'
}

artifacts {
  spi spiJar
}

// tag::dists[]
task dist(type: Zip) {
    dependsOn spiJar
    from 'src/dist'
    into('libs') {
        from spiJar.archivePath
        from configurations.runtime
    }
}

artifacts {
   archives dist
}
// end::dists[]

// We want to test if commons-math was properly added to the build script classpath
org.apache.commons.math3.fraction.Fraction lhs = new org.apache.commons.math3.fraction.Fraction(1, 3);
org.gradle.buildsrc.BuildSrcClass bsc = new org.gradle.buildsrc.BuildSrcClass()

task checkProjectDependency(dependsOn: project(':shared').jar) {
    doLast {
        File cachedSharedJarDir = new File(gradle.gradleUserHomeDir, "cache/multiproject/shared/jars")
        copy {
            from project(':shared').jar.archivePath
            into cachedSharedJarDir
        }
        File sharedJar = configurations.compile.find { File file -> file.name.startsWith('shared') }
        assert sharedJar.absolutePath == project(':shared').jar.archivePath.absolutePath
    }
}
