1+ import java.net.URI
2+
13plugins {
24 alias(libs.plugins.android.library)
35 alias(libs.plugins.kotlin.android)
@@ -8,6 +10,7 @@ plugins {
810 alias(libs.plugins.maven.publish)
911 signing
1012 id(" tech.apter.junit5.jupiter.robolectric-extension-gradle-plugin" ) version " 0.9.0"
13+ id(" me.champeau.gradle.japicmp" ) version " 0.4.5"
1114}
1215
1316android {
@@ -168,3 +171,58 @@ mavenPublishing {
168171signing {
169172 useGpgCmd()
170173}
174+
175+ // API compatibility checking with japicmp
176+ // Compares the current build against the latest released version on Maven Central
177+ // Update this version after each release (the release script should do this automatically)
178+ val baselineVersion = " 0.1.0"
179+
180+ // Download baseline AAR directly from Maven Central to avoid local project resolution
181+ val downloadBaselineAar by tasks.registering {
182+ val outputFile = layout.buildDirectory.file(" japicmp/baseline.aar" )
183+ outputs.file(outputFile)
184+ doLast {
185+ val url = " https://repo1.maven.org/maven2/com/maxmind/device/device-sdk/$baselineVersion /device-sdk-$baselineVersion .aar"
186+ val destFile = outputFile.get().asFile
187+ destFile.parentFile.mkdirs()
188+ URI (url).toURL().openStream().use { input ->
189+ destFile.outputStream().use { output ->
190+ input.copyTo(output)
191+ }
192+ }
193+ logger.lifecycle(" Downloaded baseline AAR from $url " )
194+ }
195+ }
196+
197+ // Extract classes.jar from baseline AAR for comparison
198+ val extractBaselineClasses by tasks.registering(Copy ::class ) {
199+ dependsOn(downloadBaselineAar)
200+ from(zipTree(layout.buildDirectory.file(" japicmp/baseline.aar" ))) {
201+ include(" classes.jar" )
202+ }
203+ into(layout.buildDirectory.dir(" japicmp/baseline" ))
204+ }
205+
206+ // Extract classes.jar from current AAR for comparison
207+ val extractCurrentClasses by tasks.registering(Copy ::class ) {
208+ dependsOn(" bundleReleaseAar" )
209+ from(zipTree(layout.buildDirectory.file(" outputs/aar/device-sdk-release.aar" ))) {
210+ include(" classes.jar" )
211+ }
212+ into(layout.buildDirectory.dir(" japicmp/current" ))
213+ }
214+
215+ tasks.register< me.champeau.gradle.japicmp.JapicmpTask > (" japicmp" ) {
216+ dependsOn(extractBaselineClasses, extractCurrentClasses)
217+ oldClasspath.from(layout.buildDirectory.file(" japicmp/baseline/classes.jar" ))
218+ newClasspath.from(layout.buildDirectory.file(" japicmp/current/classes.jar" ))
219+ oldArchives.from(layout.buildDirectory.file(" japicmp/baseline/classes.jar" ))
220+ newArchives.from(layout.buildDirectory.file(" japicmp/current/classes.jar" ))
221+ accessModifier.set(" public" )
222+ onlyModified.set(true )
223+ failOnModification.set(true )
224+ includeSynthetic.set(false )
225+ ignoreMissingClasses.set(true )
226+ txtOutputFile.set(layout.buildDirectory.file(" japicmp/report.txt" ))
227+ htmlOutputFile.set(layout.buildDirectory.file(" japicmp/report.html" ))
228+ }
0 commit comments