Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses some Gradle 9 breaking changes #200

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo-project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tasks.jacocoAggregatedReport {
}

val reportsSpec = copySpec {
val tookRegEx = "\\b\\d+\\.\\d+s\\b".toRegex()
val tookRegEx = "\\b\\d+(?:\\.\\d+)?s\\b".toRegex()

from(tasks.jacocoAggregatedReport) { include("**/*.csv") }
from(tasks.testAggregatedReport) {
Expand Down
1 change: 0 additions & 1 deletion demo-project/kmp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension

plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h2>Tests</h2>
<tr>
<td class="success">testKMPObject</td>
<td class="success">testKMPObject</td>
<td class="success">0s</td>
<td class="success">0.100s</td>
<td class="success">passed</td>
</tr>
</table>
Expand Down
2 changes: 1 addition & 1 deletion demo-project/ui-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdk = libs.versions.android.minSDK.get().toInt()
}

targetProjectPath = projects.demoProject.app.dependencyProject.path
targetProjectPath = projects.demoProject.app.path

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package io.github.gmazzo.android.test.aggregation

import com.android.build.api.dsl.BuildType
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.android.build.api.variant.HasUnitTest
import com.android.build.api.variant.ScopedArtifacts
import com.android.build.api.variant.Variant
import com.android.build.gradle.tasks.factory.AndroidUnitTest
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
Expand All @@ -17,9 +18,7 @@
import org.gradle.api.file.Directory
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.RegularFile
import org.gradle.api.internal.provider.Providers
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Sync
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.AbstractTestTask
Expand All @@ -35,9 +34,7 @@
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.invoke
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME

abstract class AndroidTestCoverageAggregationPlugin : Plugin<Project> {
Expand Down Expand Up @@ -201,6 +198,11 @@
}

private val TaskProvider<AbstractTestTask>.execData
get() = map { it.the<JacocoTaskExtension>().destinationFile!! }
get() = map {
when (it) {

Check warning on line 202 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt#L201-L202

Added lines #L201 - L202 were not covered by tests
is AndroidUnitTest -> it.jacocoCoverageOutputFile
else -> it.the<JacocoTaskExtension>().destinationFile
}
}

Check warning on line 206 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt#L204-L206

Added lines #L204 - L206 were not covered by tests

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.gmazzo.android.test.aggregation
import com.android.build.api.variant.HasUnitTest
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.attributes.Category
import org.gradle.api.attributes.TestSuiteType
import org.gradle.api.attributes.Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ import com.android.build.gradle.BaseExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.testing.AbstractTestTask
import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.aggregateTestCoverage
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.testAggregation
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainer
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget

internal val Project.android
Expand Down Expand Up @@ -64,7 +61,7 @@ internal fun TestAggregationExtension.aggregateProject(project: Project, config:
config.dependencies.add(project.dependencies.testAggregation(project))

private fun TestAggregationExtension.Modules.includes(project: Project) =
(includes.get().isEmpty() || project in includes.get()) && project !in excludes.get()
(includes.get().isEmpty() || project.path in includes.get()) && project.path !in excludes.get()

internal fun Project.unitTestTaskOf(variant: Variant) = (variant as? HasUnitTest)
?.unitTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,37 @@
*/
abstract class Modules {

abstract val includes: SetProperty<Project>
/**
* List of [Project.getPath] that should be included in the aggregation. If empty, all projects are included
*/
abstract val includes: SetProperty<String>

abstract val excludes: SetProperty<Project>
/**
* List of [Project.getPath] that should be excluded from the aggregation
*/
abstract val excludes: SetProperty<String>

fun include(vararg includes: Project) = apply {
this.includes.addAll(*includes)
this.includes.addAll(includes.map { it.path })

Check warning on line 33 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L33

Added line #L33 was not covered by tests
}

fun include(includes: Iterable<Project>) = apply {
this.includes.addAll(includes)
this.includes.addAll(includes.map { it.path })

Check warning on line 37 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L37

Added line #L37 was not covered by tests
}

fun include(vararg includes: ProjectDependency) =
include(includes.map { it.dependencyProject })
this.includes.addAll(includes.map { it.path })

Check warning on line 41 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L41

Added line #L41 was not covered by tests

fun exclude(vararg excludes: Project) = apply {
this.excludes.addAll(*excludes)
this.excludes.addAll(excludes.map { it.path })

Check warning on line 44 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L44

Added line #L44 was not covered by tests
}

fun exclude(excludes: Iterable<Project>) = apply {
this.excludes.addAll(excludes)
this.excludes.addAll(excludes.map { it.path })

Check warning on line 48 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L48

Added line #L48 was not covered by tests
}

fun exclude(vararg excludes: ProjectDependency) =
exclude(excludes.map { it.dependencyProject })
this.excludes.addAll(excludes.map { it.path })

Check warning on line 52 in plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/TestAggregationExtension.kt#L52

Added line #L52 was not covered by tests

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.attributes.Usage
import org.gradle.api.internal.artifacts.dependencies.AbstractModuleDependency
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.provider.Property
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget

const val USAGE_TEST_AGGREGATION = "test-aggregation"

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

UsageTestAggregationCompatibilityRule.bind(attributesSchema)

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