apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' // Required by bintray version = '1.2.2' group = 'com.otaliastudios' //region android dependencies android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName project.version testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { debug { testCoverageEnabled true } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main.java.srcDirs += 'src/main/options' main.java.srcDirs += 'src/main/views' main.java.srcDirs += 'src/main/utils' } } dependencies { testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' androidTestCompile 'com.android.support.test:runner:1.0.1' androidTestCompile 'com.android.support.test:rules:1.0.1' androidTestCompile 'com.google.dexmaker:dexmaker:1.2' androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1' compile "com.android.support:exifinterface:$supportLibVersion" compile "com.android.support:support-annotations:$supportLibVersion" } //endregion //region bintray install { repositories.mavenInstaller { pom.project { name 'CameraView' description 'A well documented, high-level Android interface that makes capturing pictures ' + 'and videos easy, addressing most of the common issues and needs.' url 'https://github.com/natario1/CameraView' packaging 'aar' groupId project.group artifactId 'cameraview' version project.version licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } scm { connection 'https://github.com/natario1/CameraView.git' developerConnection 'https://github.com/natario1/CameraView.git' url 'https://github.com/natario1/CameraView' } developers { developer { id = 'natario' name 'Natario' } } } } } def bintrayUser def bintrayKey def travis = System.getenv("TRAVIS") if (travis) { bintrayUser = System.getenv("BINTRAY_USER") bintrayKey = System.getenv("BINTRAY_KEY") } else { Properties props = new Properties() props.load(project.rootProject.file('local.properties').newDataInputStream()) bintrayUser = props.getProperty('bintray.user') bintrayKey = props.get('bintray.key') } bintray { // https://github.com/bintray/gradle-bintray-plugin user = bintrayUser key = bintrayKey configurations = ['archives'] pkg { repo = 'android' name = 'CameraView' licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/natario1/CameraView.git' publish = true override = true version { name = project.version desc = 'CameraView v. '+project.version released = new Date() vcsTag = 'v'+project.version } } } //endregion //region javadoc and sources // From official sample https://github.com/bintray/bintray-examples/blob/master/gradle-aar-example/build.gradle task sourcesJar(type: Jar) { classifier = 'sources' from android.sourceSets.main.java.sourceFiles } task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) classpath += project.files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar") project.android.libraryVariants.all { variant -> if (variant.name == 'release') { classpath += files(variant.javaCompile.classpath) } } exclude '**/BuildConfig.java' exclude '**/R.java' exclude '**/internal/**' } task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { archives javadocJar archives sourcesJar } //endregion //region code coverage // 1. running androidTests with connectedCheck will generate an .ec file // in build/outputs/code-coverage/connected, plus the XML result in // in build/reports/coverage/debug/report.xml . // 2. running unit tests with testDebugUnitTest will just generate the .exec file. // The JacocoReport task from the jacoco plugin can create the XML report out of it. // to have a unified report, we just pass both the .exec and the .ec file // to the jacoco task, so we get a unified XML report with total coverage. // Reference: https://medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa apply plugin: 'jacoco' def reportsDirectory = "$buildDir/reports/" jacoco { // Using a different version might get 0 coverage reports. // No time to investigate now. toolVersion = "0.7.6.201602180812" reportsDir = file(reportsDirectory) } task mergedCoverageReport(type: JacocoReport) { dependsOn "testDebugUnitTest" dependsOn "connectedCheck" def testData = "jacoco/testDebugUnitTest.exec" def androidTestData = "outputs/code-coverage/connected/*coverage.ec" executionData = fileTree(dir: "$buildDir", includes: [testData, androidTestData]) // Sources. sourceDirectories = android.sourceSets.main.java.sourceFiles // Add BuildConfig and R. additionalSourceDirs = files([ "$buildDir/generated/source/buildConfig/debug", "$buildDir/generated/source/r/debug" ]) // Classes. def debugDir = "$buildDir/intermediates/classes/debug" def filter = ['**/R.class', '**/R$*.class', '**/*$ViewInjector*.*', '**/BuildConfig.*', '**/Manifest*.*'] classDirectories = fileTree(dir: debugDir, excludes: filter); reports.xml.enabled = true reports.html.enabled = true reports.xml.destination = "$reportsDirectory/mergedCoverageReport/report.xml" } //endregion // export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home // To deploy ./gradlew bintrayUpload