Skip to content

Commit

Permalink
feat: Make upstream dependencies compileOnly in integrations (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Jul 18, 2022
1 parent 1c65cc8 commit 504fce8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Switch upstream dependencies to `compileOnly` in integrations ([#2175](https://github.com/getsentry/sentry-java/pull/2175))

### Fixes

- Lazily retrieve HostnameCache in MainEventProcessor ([#2170](https://github.com/getsentry/sentry-java/pull/2170))
Expand Down
3 changes: 2 additions & 1 deletion sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ android {

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

// needed because of Kotlin 1.4.x
Expand Down Expand Up @@ -107,4 +106,6 @@ dependencies {
testImplementation(projects.sentryTestSupport)
testImplementation(projects.sentryAndroidFragment)
testImplementation(projects.sentryAndroidTimber)
testRuntimeOnly(Config.Libs.timber)
testRuntimeOnly(Config.Libs.fragment)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public final class SentryAndroid {
static final String SENTRY_TIMBER_INTEGRATION_CLASS_NAME =
"io.sentry.android.timber.SentryTimberIntegration";

private static final String TIMBER_CLASS_NAME = "timber.log.Timber";
private static final String FRAGMENT_CLASS_NAME =
"androidx.fragment.app.FragmentManager$FragmentLifecycleCallbacks";

private SentryAndroid() {}

/**
Expand Down Expand Up @@ -84,10 +88,17 @@ public static synchronized void init(
OptionsContainer.create(SentryAndroidOptions.class),
options -> {
final LoadClass classLoader = new LoadClass();
final boolean isTimberUpstreamAvailable =
classLoader.isClassAvailable(TIMBER_CLASS_NAME, options);
final boolean isFragmentUpstreamAvailable =
classLoader.isClassAvailable(FRAGMENT_CLASS_NAME, options);
final boolean isFragmentAvailable =
classLoader.isClassAvailable(SENTRY_FRAGMENT_INTEGRATION_CLASS_NAME, options);
(isFragmentUpstreamAvailable
&& classLoader.isClassAvailable(
SENTRY_FRAGMENT_INTEGRATION_CLASS_NAME, options));
final boolean isTimberAvailable =
classLoader.isClassAvailable(SENTRY_TIMBER_INTEGRATION_CLASS_NAME, options);
(isTimberUpstreamAvailable
&& classLoader.isClassAvailable(SENTRY_TIMBER_INTEGRATION_CLASS_NAME, options));

AndroidOptionsInitializer.init(
options, context, logger, isFragmentAvailable, isTimberAvailable);
Expand Down
3 changes: 2 additions & 1 deletion sentry-android-fragment/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ kotlin {
dependencies {
api(projects.sentry)

implementation(Config.Libs.fragment)
compileOnly(Config.Libs.fragment)

// tests
testImplementation(Config.Libs.fragment)
testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
testImplementation(Config.TestLibs.mockitoInline)
Expand Down
6 changes: 4 additions & 2 deletions sentry-android-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ kotlin {
dependencies {
api(projects.sentry)

implementation(Config.Libs.okhttpBom)
implementation(Config.Libs.okhttp)
compileOnly(Config.Libs.okhttpBom)
compileOnly(Config.Libs.okhttp)

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

// tests
testImplementation(Config.Libs.okhttpBom)
testImplementation(Config.Libs.okhttp)
testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.androidxJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
Expand Down
3 changes: 2 additions & 1 deletion sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ kotlin {
dependencies {
api(projects.sentry)

api(Config.Libs.timber)
compileOnly(Config.Libs.timber)

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

// tests
testImplementation(Config.Libs.timber)
testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.androidxJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
Expand Down
1 change: 1 addition & 0 deletions sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {
implementation(projects.sentryAndroidTimber)
implementation(projects.sentryCompose)
implementation(Config.Libs.fragment)
implementation(Config.Libs.timber)

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

0 comments on commit 504fce8

Please sign in to comment.