-
Notifications
You must be signed in to change notification settings - Fork 20
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
Switch to using gradle artifact APIs for root project tasks #704
Changes from all commits
8613c24
764b385
704cabb
7ef71a3
2973d53
28b62a9
c0e40eb
e9903c6
cac757f
c74cbc8
dc27c61
a5eeadd
587f39e
0f15a68
5c61204
043c4fa
5183ab6
8d1028b
e25b66a
90fb7df
c48eb58
844741d
cf6e2c5
9b552d7
2cca512
1c88e81
c0046c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"issues":[{"type":"get_subprojects","name":"getSubprojects","trace":{"trace":[{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver$default","descriptor":"(Lslack/gradle/artifacts/Resolver$Companion;Lorg/gradle/api/Project;Lorg/gradle/api/attributes/Attribute;Ljava/io/Serializable;Ljava/lang/String;ZILjava/lang/Object;)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver","descriptor":"(Lorg/gradle/api/Project;Lorg/gradle/api/attributes/Attribute;Ljava/io/Serializable;Ljava/lang/String;Z)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver","name":"addSubprojectDependencies","descriptor":"(Lorg/gradle/api/Project;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"org/gradle/api/Project","name":"getSubprojects","descriptor":"()Ljava/util/Set;","metadata":{"isTaskAction":false,"isVirtual":false}}]}},{"type":"get_subprojects","name":"getSubprojects","trace":{"trace":[{"owner":"slack/stats/ModuleStatsTasks$configureRoot$1$1","name":"call","descriptor":"()Ljava/lang/Object;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/stats/ModuleStatsTasks$configureRoot$1$1","name":"call","descriptor":"()Ljava/util/Map;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"org/gradle/api/Project","name":"getSubprojects","descriptor":"()Ljava/util/Set;","metadata":{"isTaskAction":false,"isVirtual":false}}]}},{"type":"get_subprojects","name":"getSubprojects","trace":{"trace":[{"owner":"slack/gradle/SlackRootPlugin","name":"apply","descriptor":"(Ljava/lang/Object;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/SlackRootPlugin","name":"apply","descriptor":"(Lorg/gradle/api/Project;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/SlackRootPlugin","name":"configureRootProject","descriptor":"(Lorg/gradle/api/Project;Lslack/gradle/SlackProperties;Lorg/gradle/api/provider/Provider;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/tasks/AndroidTestApksTask$Companion","name":"register$slack_plugin","descriptor":"(Lorg/gradle/api/Project;)Lorg/gradle/api/tasks/TaskProvider;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver$default","descriptor":"(Lslack/gradle/artifacts/Resolver$Companion;Lorg/gradle/api/Project;Lslack/gradle/artifacts/SgpArtifact;ZILjava/lang/Object;)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver","descriptor":"(Lorg/gradle/api/Project;Lslack/gradle/artifacts/SgpArtifact;Z)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver","descriptor":"(Lorg/gradle/api/Project;Lorg/gradle/api/attributes/Attribute;Ljava/io/Serializable;Ljava/lang/String;Z)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver","name":"addSubprojectDependencies","descriptor":"(Lorg/gradle/api/Project;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"org/gradle/api/Project","name":"getSubprojects","descriptor":"()Ljava/util/Set;","metadata":{"isTaskAction":false,"isVirtual":false}}]}},{"type":"get_subprojects","name":"getSubprojects","trace":{"trace":[{"owner":"slack/gradle/SlackRootPlugin$configureRootProject$10","name":"execute","descriptor":"(Ljava/lang/Object;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/SlackRootPlugin$configureRootProject$10","name":"execute","descriptor":"(Lorg/gradle/api/plugins/AppliedPlugin;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/dependencyrake/MissingIdentifiersAggregatorTask$Companion","name":"register","descriptor":"(Lorg/gradle/api/Project;)Lorg/gradle/api/tasks/TaskProvider;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver$default","descriptor":"(Lslack/gradle/artifacts/Resolver$Companion;Lorg/gradle/api/Project;Lslack/gradle/artifacts/SgpArtifact;ZILjava/lang/Object;)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver","descriptor":"(Lorg/gradle/api/Project;Lslack/gradle/artifacts/SgpArtifact;Z)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver$Companion","name":"interProjectResolver","descriptor":"(Lorg/gradle/api/Project;Lorg/gradle/api/attributes/Attribute;Ljava/io/Serializable;Ljava/lang/String;Z)Lslack/gradle/artifacts/Resolver;","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"slack/gradle/artifacts/Resolver","name":"addSubprojectDependencies","descriptor":"(Lorg/gradle/api/Project;)V","metadata":{"isTaskAction":false,"isVirtual":false}},{"owner":"org/gradle/api/Project","name":"getSubprojects","descriptor":"()Ljava/util/Set;","metadata":{"isTaskAction":false,"isVirtual":false}}]}}]} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,3 +321,13 @@ internal inline fun <reified T : Any> Project.serviceOf(): T = | |
(this as ProjectInternal).services.get() | ||
|
||
internal inline fun <reified T : Any> ServiceRegistry.get(): T = this[T::class.java]!! | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
internal inline fun <reified T : Task> TaskContainer.registerOrConfigure( | ||
taskName: String, | ||
crossinline configureAction: T.() -> Unit | ||
): TaskProvider<T> = | ||
when (taskName) { | ||
in names -> named(taskName) as TaskProvider<T> | ||
else -> register(taskName, T::class.java) | ||
}.apply { configure { configureAction() } } | ||
Comment on lines
+325
to
+333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a neat pattern |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,19 +57,21 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension | |
import org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask | ||
import org.jetbrains.kotlin.gradle.plugin.KaptExtension | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin | ||
import org.jetbrains.kotlin.gradle.utils.named | ||
import slack.dependencyrake.MissingIdentifiersAggregatorTask | ||
import slack.dependencyrake.RakeDependencies | ||
import slack.gradle.AptOptionsConfig.AptOptionsConfigurer | ||
import slack.gradle.AptOptionsConfigs.invoke | ||
import slack.gradle.avoidance.ComputeAffectedProjectsTask | ||
import slack.gradle.artifacts.Publisher | ||
import slack.gradle.artifacts.SgpArtifact | ||
import slack.gradle.dependencies.BuildConfig | ||
import slack.gradle.dependencies.SlackDependencies | ||
import slack.gradle.lint.DetektTasks | ||
import slack.gradle.lint.LintTasks | ||
import slack.gradle.permissionchecks.PermissionChecks | ||
import slack.gradle.tasks.AndroidTestApksTask | ||
import slack.gradle.tasks.CheckManifestPermissionsTask | ||
import slack.gradle.tasks.SimpleFileProducerTask | ||
import slack.gradle.tasks.publishWith | ||
import slack.gradle.tasks.robolectric.UpdateRobolectricJarsTask | ||
import slack.gradle.util.booleanProperty | ||
import slack.gradle.util.configureKotlinCompilationTask | ||
import slack.gradle.util.setDisallowChanges | ||
|
@@ -231,13 +233,9 @@ internal class StandardProjectConfigurations( | |
configure<DependencyAnalysisSubExtension> { | ||
registerPostProcessingTask(rakeDependencies) | ||
} | ||
val aggregator = | ||
project.rootProject.tasks.named<MissingIdentifiersAggregatorTask>( | ||
MissingIdentifiersAggregatorTask.NAME | ||
) | ||
aggregator.configure { | ||
inputFiles.from(rakeDependencies.flatMap { it.missingIdentifiersFile }) | ||
} | ||
val publisher = | ||
Publisher.interProjectPublisher(project, SgpArtifact.DAGP_MISSING_IDENTIFIERS) | ||
publisher.publish(rakeDependencies.flatMap { it.missingIdentifiersFile }) | ||
} | ||
} | ||
} | ||
|
@@ -449,16 +447,13 @@ internal class StandardProjectConfigurations( | |
slackProperties: SlackProperties, | ||
) { | ||
val javaVersion = JavaVersion.toVersion(jvmTargetVersion) | ||
val computeAffectedProjectsTask = | ||
project.rootProject.tasks.named( | ||
ComputeAffectedProjectsTask.NAME, | ||
ComputeAffectedProjectsTask::class.java | ||
) | ||
// Contribute these libraries to Fladle if they opt into it | ||
val androidTestApksAggregator = | ||
project.rootProject.tasks.named(AndroidTestApksTask.NAME, AndroidTestApksTask::class.java) | ||
val androidTestApksPublisher = | ||
Publisher.interProjectPublisher(project, SgpArtifact.ANDROID_TEST_APK_DIRS) | ||
val projectPath = project.path | ||
val isAffectedProject = slackTools.globalConfig.affectedProjects?.contains(projectPath) ?: true | ||
val skippyAndroidTestProjectPublisher = | ||
Publisher.interProjectPublisher(project, SgpArtifact.SKIPPY_ANDROID_TEST_PROJECT) | ||
|
||
val commonComponentsExtension = | ||
Action<AndroidComponentsExtension<*, *, *>> { | ||
|
@@ -505,12 +500,22 @@ internal class StandardProjectConfigurations( | |
val isAndroidTestEnabled = variant is HasAndroidTest && variant.androidTest != null | ||
if (isAndroidTestEnabled) { | ||
if (!excluded && isAffectedProject) { | ||
computeAffectedProjectsTask.configure { androidTestProjects.add(projectPath) } | ||
// Note this intentionally just uses the same task each time as they always produce | ||
// the same output | ||
SimpleFileProducerTask.registerOrConfigure( | ||
project, | ||
name = "androidTestProjectMetadata", | ||
description = | ||
"Produces a metadata artifact indicating this project path produces an androidTest APK.", | ||
input = projectPath, | ||
group = "skippy" | ||
) | ||
.publishWith(skippyAndroidTestProjectPublisher) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
if (isLibraryVariant) { | ||
(variant as LibraryVariant).androidTest?.artifacts?.get(SingleArtifact.APK)?.let { | ||
apkArtifactsDir -> | ||
// Wire this up to the aggregator | ||
androidTestApksAggregator.configure { androidTestApkDirs.from(apkArtifactsDir) } | ||
// Wire this up to the aggregator. No need for an intermediate task here. | ||
androidTestApksPublisher.publishDirs(apkArtifactsDir) | ||
} | ||
} | ||
} else { | ||
|
@@ -588,12 +593,12 @@ internal class StandardProjectConfigurations( | |
// | ||
// Note that we can't configure this to _just_ be enabled for robolectric projects | ||
// based on dependencies unfortunately, as the task graph is already wired by the | ||
// time | ||
// dependencies start getting resolved. | ||
// time dependencies start getting resolved. | ||
// | ||
slackTools.globalConfig.updateRobolectricJarsTask?.let { | ||
slackProperties.versions.robolectric?.let { | ||
logger.debug("Configuring $name test task to depend on Robolectric jar downloads") | ||
test.dependsOn(it) | ||
// Depending on the root project task by name alone is ok for Project Isolation | ||
test.dependsOn(UpdateRobolectricJarsTask.NAME) | ||
Comment on lines
+600
to
+601
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh gradle 👨🍳 💋 |
||
} | ||
|
||
// Necessary for some OkHttp-using tests to work on JDK 11 in Robolectric | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I like this, I will probably steal it