@@ -8,6 +8,7 @@ plugins {
88 alias(libs.plugins.maven.publish)
99 signing
1010 id(" tech.apter.junit5.jupiter.robolectric-extension-gradle-plugin" ) version " 0.9.0"
11+ id(" me.champeau.gradle.japicmp" ) version " 0.4.5"
1112}
1213
1314android {
@@ -168,3 +169,59 @@ mavenPublishing {
168169signing {
169170 useGpgCmd()
170171}
172+
173+ // API compatibility checking with japicmp
174+ // Compares the current build against the latest released version on Maven Central
175+ // Update this version after each release (the release script should do this automatically)
176+ val baselineVersion = " 0.1.0"
177+
178+ // Download baseline AAR directly from Maven Central to avoid local project resolution
179+ val downloadBaselineAar by tasks.registering {
180+ val outputFile = layout.buildDirectory.file(" japicmp/baseline.aar" )
181+ outputs.file(outputFile)
182+ doLast {
183+ val url = " https://repo1.maven.org/maven2/com/maxmind/device/device-sdk/$baselineVersion /device-sdk-$baselineVersion .aar"
184+ val destFile = outputFile.get().asFile
185+ destFile.parentFile.mkdirs()
186+ java.net.URI (url).toURL().openStream().use { input ->
187+ destFile.outputStream().use { output ->
188+ input.copyTo(output)
189+ }
190+ }
191+ logger.lifecycle(" Downloaded baseline AAR from $url " )
192+ }
193+ }
194+
195+ // Extract classes.jar from baseline AAR for comparison
196+ val extractBaselineClasses by tasks.registering(Copy ::class ) {
197+ dependsOn(downloadBaselineAar)
198+ from(zipTree(layout.buildDirectory.file(" japicmp/baseline.aar" ))) {
199+ include(" classes.jar" )
200+ rename(" classes.jar" , " baseline-classes.jar" )
201+ }
202+ into(layout.buildDirectory.dir(" japicmp" ))
203+ }
204+
205+ // Extract classes.jar from current AAR for comparison
206+ val extractCurrentClasses by tasks.registering(Copy ::class ) {
207+ dependsOn(" bundleReleaseAar" )
208+ from(zipTree(layout.buildDirectory.file(" outputs/aar/device-sdk-release.aar" ))) {
209+ include(" classes.jar" )
210+ rename(" classes.jar" , " current-classes.jar" )
211+ }
212+ into(layout.buildDirectory.dir(" japicmp" ))
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+ txtOutputFile.set(layout.buildDirectory.file(" japicmp/report.txt" ))
226+ htmlOutputFile.set(layout.buildDirectory.file(" japicmp/report.html" ))
227+ }
0 commit comments