Skip to content

Commit 6509ada

Browse files
committed
Cleanup sentry.options.json from assets after the build
1 parent ff20ed9 commit 6509ada

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

packages/core/sentry.gradle

+20-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
33
import java.util.regex.Matcher
44
import java.util.regex.Pattern
55

6-
project.ext.shouldSentryAutoUploadNative = { ->
6+
project.ext.shouldSentryAutoUploadNative = { ->
77
return System.getenv('SENTRY_DISABLE_NATIVE_DEBUG_UPLOAD') != 'true'
88
}
99

@@ -17,13 +17,13 @@ project.ext.shouldSentryAutoUpload = { ->
1717

1818
def config = project.hasProperty("sentryCli") ? project.sentryCli : [];
1919

20+
def configFile = "sentry.options.json" // Sentry condiguration file
21+
def androidAssetsDir = new File("$rootDir/app/src/main/assets") // Path to Android assets folder
22+
2023
tasks.register("copySentryJsonConfiguration") {
2124
doLast {
22-
def configFile = "sentry.options.json"
2325
def appRoot = project.rootDir.parentFile ?: project.rootDir
2426
def sentryOptionsFile = new File(appRoot, configFile)
25-
def androidAssetsDir = new File("$rootDir/app/src/main/assets") // Path to Android assets folder
26-
2727
if (sentryOptionsFile.exists()) {
2828
if (!androidAssetsDir.exists()) {
2929
androidAssetsDir.mkdirs()
@@ -41,11 +41,27 @@ tasks.register("copySentryJsonConfiguration") {
4141
}
4242
}
4343

44+
tasks.register("cleanupTemporarySentryJsonConfiguration") {
45+
doLast {
46+
def sentryOptionsFile = new File(androidAssetsDir, configFile)
47+
if (sentryOptionsFile.exists()) {
48+
logger.lifecycle("Deleting temporary file: ${sentryOptionsFile.path}")
49+
sentryOptionsFile.delete()
50+
}
51+
}
52+
}
53+
4454
gradle.projectsEvaluated {
4555
// Add a task that copies the sentry.options.json file before the build starts
4656
tasks.named("preBuild").configure {
4757
dependsOn("copySentryJsonConfiguration")
4858
}
59+
// Cleanup sentry.options.json from assets after the build
60+
tasks.matching { task ->
61+
task.name == "build" || task.name.startsWith("assemble") || task.name.startsWith("install")
62+
}.configureEach {
63+
finalizedBy("cleanupTemporarySentryJsonConfiguration")
64+
}
4965

5066
def releases = extractReleasesInfo()
5167

0 commit comments

Comments
 (0)