apply plugin: 'com.android.library' def groupId = "com.ichi2.anki" def artifactId = "api" def version = "1.1.0alpha6" repositories { google() jcenter() } android { compileSdkVersion 28 defaultConfig { minSdkVersion 8 targetSdkVersion 28 versionCode 11016 // 4th digit: 1=alpha, 2=beta, 3=official versionName version } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } testOptions { unitTests { includeAndroidResources = true } } testOptions.unitTests.all { testLogging { events "failed", "skipped" showStackTraces = true exceptionFormat = "full" } maxParallelForks = gradleTestMaxParallelForks } } dependencies { api fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'org.junit.vintage:junit-vintage-engine:5.3.2' testImplementation "org.robolectric:robolectric:4.0.2" } // Borrowed from here: // http://blog.blundell-apps.com/locally-release-an-android-library-for-jcenter-or-maven-central-inclusion/ apply plugin: 'maven' def localReleaseDest = "${buildDir}/release/${version}" task androidJavadocs(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) // Java 10 wants you to choose between html4 and html5. We are html5 clean and should use it. // But in JDK < 10 the option isn't there and it breaks the build. This handles both. if(JavaVersion.current() >= JavaVersion.VERSION_1_10){ options.addBooleanOption('html5', true) } } // Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:deprecation" << "-Xmaxwarns" << "1000" << "-Werror" } task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { classifier = 'javadoc' from androidJavadocs.destinationDir } task androidSourcesJar(type: Jar) { classifier = 'sources' from android.sourceSets.main.java.srcDirs } uploadArchives { repositories.mavenDeployer { pom.groupId = groupId pom.artifactId = artifactId pom.version = version // Add other pom properties here if you want (developer details / licenses) repository(url: "file://${localReleaseDest}") } } task zipRelease(type: Zip) { from localReleaseDest destinationDir buildDir archiveName "release-${version}.zip" } task generateRelease { doLast { println "Release ${version} can be found at ${localReleaseDest}/" println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip" } } generateRelease.dependsOn(uploadArchives) generateRelease.dependsOn(zipRelease) artifacts { archives androidSourcesJar archives androidJavadocsJar } // Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:deprecation" << "-Xmaxwarns" << "1000" << "-Werror" // https://guides.gradle.org/performance/#compiling_java // 1- fork improves things over time with repeated builds, doesn't harm CI single builds options.fork = true // 2- incremental will be the default in the future and can help now options.incremental = true }