diff --git a/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt b/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt index 705ab6a..47d49c7 100644 --- a/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt +++ b/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt @@ -1,13 +1,9 @@ package com.dropbox.focus -import java.io.Serializable import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.provider.SetProperty -import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.gradle.work.DisableCachingByDefault @@ -15,33 +11,19 @@ import org.gradle.work.DisableCachingByDefault @DisableCachingByDefault(because = "Not worth caching") public abstract class CreateFocusSettingsTask : DefaultTask() { - @get:Input - protected abstract val projectDeps: SetProperty - - @get:Input - protected abstract val projectPath: Property - @get:OutputFile public abstract val settingsFile: RegularFileProperty @get:OutputFile public abstract val modulesToDirMapFile: RegularFileProperty - /** - * Project info required for focus.settings.gradle generation. - */ - protected data class DependentProjectInfo( - public val path: String, - public val projectDir: String, - ): Serializable - init { outputs.upToDateWhen { false } } @TaskAction public fun createFocusSettings() { - val dependencies = projectDeps.get().sortedBy { it.path } + val dependencies = project.collectDependencies().sortedBy { it.path } // generate CSV mapping from module name to its absolute path modulesToDirMapFile.get().asFile.writer().use { writer -> @@ -55,7 +37,7 @@ public abstract class CreateFocusSettingsTask : DefaultTask() { } settingsFile.get().asFile.writer().use { writer -> - writer.write("// ${projectPath.get()} specific settings\n") + writer.write("// ${project.path} specific settings\n") writer.appendLine("//") writer.appendLine("// This file is autogenerated by the focus task. Changes will be overwritten.") writer.appendLine() @@ -78,12 +60,11 @@ public abstract class CreateFocusSettingsTask : DefaultTask() { } } - private fun Project.collectDependencies(): Set { - val result = mutableSetOf() + private fun Project.collectDependencies(): Set { + val result = mutableSetOf() fun addDependent(project: Project) { val configuredProject = this.evaluationDependsOn(project.path) - val dep = DependentProjectInfo(project.path, project.projectDir.absolutePath) - if (result.add(dep)) { + if (result.add(configuredProject)) { configuredProject.configurations.forEach { config -> config.dependencies .filterIsInstance() @@ -102,10 +83,7 @@ public abstract class CreateFocusSettingsTask : DefaultTask() { group = FOCUS_TASK_GROUP settingsFile.set(subExtension.focusSettingsFile) modulesToDirMapFile.set(subExtension.moduleToDirMapFile) - projectPath.set(project.path) - // Collecting dependencies info in the configuration phase. - // Gradle disallows accessing project in execution phase. - projectDeps.set(project.collectDependencies()) + notCompatibleWithConfigurationCache("This reads configurations from the project at action-time.") } } } diff --git a/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt b/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt index 3f1e609..1c4fc48 100644 --- a/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt +++ b/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt @@ -22,24 +22,7 @@ class FocusPluginTest { } @Test - fun configurationCache_focus() { - val fixtureRoot = File("src/test/projects/configuration-cache-compatible") - - gradleRunner - .withArguments("--configuration-cache", "focus") - .withProjectDir(fixtureRoot) - .build() - - val result = gradleRunner - .withArguments("--configuration-cache", "focus") - .withProjectDir(fixtureRoot) - .build() - - assertThat(result.output).contains("Reusing configuration cache.") - } - - @Test - fun configurationCache_clear() { + fun configurationCache() { val fixtureRoot = File("src/test/projects/configuration-cache-compatible") gradleRunner