Skip to content

fix: declare junit as a test-only dependency - #20

Open
mattiasgeniar wants to merge 1 commit into
ionic-team:mainfrom
mattiasgeniar:fix/junit-test-scope
Open

mattiasgeniar wants to merge 1 commit into
ionic-team:mainfrom
mattiasgeniar:fix/junit-test-scope

Conversation

@mattiasgeniar

Copy link
Copy Markdown

Description

junit:junit:4.13.2 is declared twice in build.gradle: once as testImplementation (correct) and once as implementation. The implementation line puts it in the release runtime classpath, so the published POM for io.ionic.libs:ioncamera-android lists JUnit with runtime scope:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.13.2</version>
  <scope>runtime</scope>
</dependency>

This PR removes the implementation line. Nothing under src/main imports org.junit or org.hamcrest, and the unit tests keep JUnit through the existing testImplementation line.

Context

Every app that uses @capacitor/camera 8.x depends on this library, so it ships JUnit and its Hamcrest dependency inside the release APK. Capacitor's app template does not enable R8 for release builds, so for most apps nothing strips these classes later.

Measured on a production Capacitor 8.5 app, release build without R8 (the template default), identical except for this dependency:

Before After Difference
APK size 12,849,908 B 12,745,218 B −104,690 B (−102 KB)
Dex classes 20,277 19,882 −395
Defined dex methods 143,623 141,468 −2,155
junit / org.junit / org.hamcrest in the dex 21 KB / 128 KB / 18 KB none

Release runtime classpath of the library itself:

./gradlew dependencies --configuration releaseRuntimeClasspath
Before junit:junit:4.13.2, org.hamcrest:hamcrest-core:1.3
After neither

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Tests

  • ./gradlew testDebugUnitTest assembleRelease on this branch: 60 tests, 0 failures, release AAR builds.
  • releaseRuntimeClasspath before and after, as in the table above.
  • APK comparison: the app's release build with exclude group: 'junit' and exclude group: 'org.hamcrest' on its releaseRuntimeClasspath, which is the dependency graph this change publishes, measured with apkanalyzer dex packages.

Screenshots (if appropriate)

n/a

Checklist

  • Code follows code style of this project
  • CHANGELOG.md file is correctly updated
  • Changes require an update to the documentation
    • Documentation has been updated accordingly

@mattiasgeniar
mattiasgeniar marked this pull request as ready for review September 30, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant