Skip to content

Commit

Permalink
Fix source and destination folders computation for Android Gradle pro…
Browse files Browse the repository at this point in the history
…jects
  • Loading branch information
nikita-tkachenko-datadog committed Jan 13, 2025
1 parent 8bcee06 commit 561e191
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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') {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 561e191

Please sign in to comment.