Skip to content

Commit

Permalink
Fixing missing UsageTestAggregationCompatibilityRule when used by r…
Browse files Browse the repository at this point in the history
…egular JVM modules
  • Loading branch information
gmazzo committed Apr 25, 2023
1 parent 6e2939f commit 2fd78c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin<Project> {
.toGet(ScopedArtifact.CLASSES, { allVariantsJars }, { allVariantsDirs })
}

dependencies.attributesSchema.attribute(Usage.USAGE_ATTRIBUTE)
.compatibilityRules
.add(UsageTestAggregationCompatibilityRule::class.java)

configurations.create("codeCoverageElements") {
isCanBeConsumed = true
isCanBeResolved = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.github.gmazzo.android.test.aggregation

import org.gradle.api.Project
import org.gradle.api.attributes.AttributeCompatibilityRule
import org.gradle.api.attributes.AttributesSchema
import org.gradle.api.attributes.CompatibilityCheckDetails
import org.gradle.api.attributes.Usage
import org.gradle.kotlin.dsl.USAGE_TEST_AGGREGATION
import org.gradle.kotlin.dsl.add

internal class UsageTestAggregationCompatibilityRule : AttributeCompatibilityRule<Usage> {

Expand All @@ -13,4 +16,19 @@ internal class UsageTestAggregationCompatibilityRule : AttributeCompatibilityRul
}
}

companion object {

fun bind(project: Project) {
bind(project.dependencies.attributesSchema)
}

fun bind(schema: AttributesSchema) {
schema
.attribute(Usage.USAGE_ATTRIBUTE)
.compatibilityRules
.add(UsageTestAggregationCompatibilityRule::class)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.gradle.kotlin.dsl

import com.android.build.api.dsl.BuildType
import com.android.build.api.dsl.ProductFlavor
import io.github.gmazzo.android.test.aggregation.UsageTestAggregationCompatibilityRule
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
Expand All @@ -12,6 +13,8 @@ const val USAGE_TEST_AGGREGATION = "test-aggregation"

fun DependencyHandler.testAggregation(dependency: Any): Dependency = create(dependency).also {
(it as? ProjectDependency)?.apply {
UsageTestAggregationCompatibilityRule.bind(dependencyProject)

attributes {
attribute(Usage.USAGE_ATTRIBUTE, dependencyProject.objects.named(USAGE_TEST_AGGREGATION))
}
Expand Down

0 comments on commit 2fd78c3

Please sign in to comment.