Skip to content

Commit 504fce8

Browse files
authored
feat: Make upstream dependencies compileOnly in integrations (#2175)
1 parent 1c65cc8 commit 504fce8

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Switch upstream dependencies to `compileOnly` in integrations ([#2175](https://github.com/getsentry/sentry-java/pull/2175))
8+
59
### Fixes
610

711
- Lazily retrieve HostnameCache in MainEventProcessor ([#2170](https://github.com/getsentry/sentry-java/pull/2170))

sentry-android-core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ android {
4949

5050
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
5151
checkReleaseBuilds = false
52-
disable += "LogNotTimber"
5352
}
5453

5554
// needed because of Kotlin 1.4.x
@@ -107,4 +106,6 @@ dependencies {
107106
testImplementation(projects.sentryTestSupport)
108107
testImplementation(projects.sentryAndroidFragment)
109108
testImplementation(projects.sentryAndroidTimber)
109+
testRuntimeOnly(Config.Libs.timber)
110+
testRuntimeOnly(Config.Libs.fragment)
110111
}

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public final class SentryAndroid {
3131
static final String SENTRY_TIMBER_INTEGRATION_CLASS_NAME =
3232
"io.sentry.android.timber.SentryTimberIntegration";
3333

34+
private static final String TIMBER_CLASS_NAME = "timber.log.Timber";
35+
private static final String FRAGMENT_CLASS_NAME =
36+
"androidx.fragment.app.FragmentManager$FragmentLifecycleCallbacks";
37+
3438
private SentryAndroid() {}
3539

3640
/**
@@ -84,10 +88,17 @@ public static synchronized void init(
8488
OptionsContainer.create(SentryAndroidOptions.class),
8589
options -> {
8690
final LoadClass classLoader = new LoadClass();
91+
final boolean isTimberUpstreamAvailable =
92+
classLoader.isClassAvailable(TIMBER_CLASS_NAME, options);
93+
final boolean isFragmentUpstreamAvailable =
94+
classLoader.isClassAvailable(FRAGMENT_CLASS_NAME, options);
8795
final boolean isFragmentAvailable =
88-
classLoader.isClassAvailable(SENTRY_FRAGMENT_INTEGRATION_CLASS_NAME, options);
96+
(isFragmentUpstreamAvailable
97+
&& classLoader.isClassAvailable(
98+
SENTRY_FRAGMENT_INTEGRATION_CLASS_NAME, options));
8999
final boolean isTimberAvailable =
90-
classLoader.isClassAvailable(SENTRY_TIMBER_INTEGRATION_CLASS_NAME, options);
100+
(isTimberUpstreamAvailable
101+
&& classLoader.isClassAvailable(SENTRY_TIMBER_INTEGRATION_CLASS_NAME, options));
91102

92103
AndroidOptionsInitializer.init(
93104
options, context, logger, isFragmentAvailable, isTimberAvailable);

sentry-android-fragment/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ kotlin {
6666
dependencies {
6767
api(projects.sentry)
6868

69-
implementation(Config.Libs.fragment)
69+
compileOnly(Config.Libs.fragment)
7070

7171
// tests
72+
testImplementation(Config.Libs.fragment)
7273
testImplementation(Config.TestLibs.kotlinTestJunit)
7374
testImplementation(Config.TestLibs.mockitoKotlin)
7475
testImplementation(Config.TestLibs.mockitoInline)

sentry-android-okhttp/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ kotlin {
6868
dependencies {
6969
api(projects.sentry)
7070

71-
implementation(Config.Libs.okhttpBom)
72-
implementation(Config.Libs.okhttp)
71+
compileOnly(Config.Libs.okhttpBom)
72+
compileOnly(Config.Libs.okhttp)
7373

7474
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
7575

7676
// tests
77+
testImplementation(Config.Libs.okhttpBom)
78+
testImplementation(Config.Libs.okhttp)
7779
testImplementation(Config.TestLibs.kotlinTestJunit)
7880
testImplementation(Config.TestLibs.androidxJunit)
7981
testImplementation(Config.TestLibs.mockitoKotlin)

sentry-android-timber/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ kotlin {
7171
dependencies {
7272
api(projects.sentry)
7373

74-
api(Config.Libs.timber)
74+
compileOnly(Config.Libs.timber)
7575

7676
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
7777

7878
// tests
79+
testImplementation(Config.Libs.timber)
7980
testImplementation(Config.TestLibs.kotlinTestJunit)
8081
testImplementation(Config.TestLibs.androidxJunit)
8182
testImplementation(Config.TestLibs.mockitoKotlin)

sentry-samples/sentry-samples-android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ dependencies {
111111
implementation(projects.sentryAndroidTimber)
112112
implementation(projects.sentryCompose)
113113
implementation(Config.Libs.fragment)
114+
implementation(Config.Libs.timber)
114115

115116
// how to exclude androidx if release health feature is disabled
116117
// implementation(projects.sentryAndroid) {

0 commit comments

Comments
 (0)