From 0ad49ee80edf155c44eded52cd2fe76345a9fcb3 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Mon, 13 Jan 2025 15:30:18 +0100 Subject: [PATCH] Fix source and destination folders computation for Android Gradle projects (cherry picked from commit 561e19147282bf0c7e0254ad73ad69aed8db17eb) --- .../gradle/AndroidGradleUtils.groovy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dd-java-agent/instrumentation/gradle-8.3/src/main/groovy/datadog/trace/instrumentation/gradle/AndroidGradleUtils.groovy b/dd-java-agent/instrumentation/gradle-8.3/src/main/groovy/datadog/trace/instrumentation/gradle/AndroidGradleUtils.groovy index 626d7fb8736..cc9fa64bd25 100644 --- a/dd-java-agent/instrumentation/gradle-8.3/src/main/groovy/datadog/trace/instrumentation/gradle/AndroidGradleUtils.groovy +++ b/dd-java-agent/instrumentation/gradle-8.3/src/main/groovy/datadog/trace/instrumentation/gradle/AndroidGradleUtils.groovy @@ -8,6 +8,9 @@ import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging import org.gradle.api.tasks.testing.Test +import java.nio.file.Files +import java.nio.file.Paths + class AndroidGradleUtils { private static final Logger LOGGER = Logging.getLogger(AndroidGradleUtils) @@ -29,7 +32,10 @@ class AndroidGradleUtils { } private static getVariant(Project project, Test task) { - def androidPlugin = project.plugins.findPlugin('android') ?: project.plugins.findPlugin('android-library') + def androidPlugin = project.plugins.findPlugin('android') + ?: project.plugins.findPlugin('android-library') + ?: project.plugins.findPlugin('com.android.application') + ?: project.plugins.findPlugin('com.android.library') def variants if (androidPlugin.class.simpleName == 'LibraryPlugin') { @@ -39,7 +45,7 @@ class AndroidGradleUtils { } for (def v : variants) { - if (task.path.endsWith("test${v.name.capitalize()}UnitTest")) { + if (task.path.endsWith("test${v.name.capitalize()}UnitTest") || task.path.endsWith("test${v.name.capitalize()}")) { return v } } @@ -75,8 +81,8 @@ class AndroidGradleUtils { FileTree javaTree = project.fileTree(dir: javaDestinations, excludes: EXCLUDES) FileTree destinationsTree - if (project.plugins.findPlugin('kotlin-android') != null) { - def kotlinDestinations = "${project.buildDir}/tmp/kotlin-classes/${variant.name}" + def kotlinDestinations = "${project.buildDir}/tmp/kotlin-classes/${variant.name}" + if (Files.exists(Paths.get(kotlinDestinations))) { def kotlinTree = project.fileTree(dir: kotlinDestinations, excludes: EXCLUDES) destinationsTree = javaTree + kotlinTree } else {