Fix failure when creating a compilation in afterEvaluate (KT-28896)
To configure a compilation's sources, we run an action in
`whenEvaluated { ... }`, expecting that the compilation's task already
exists. This was not true with compilations created from a user build
script or a 3rd-party plugin in `afterEvaluate { ... }`.
Fix this by expecting that a task may possibly not exist at that point,
and also using `whenEvaluated { ... }` instead of
`afterEvaluate { ... }` in several places that are executed for each new
compilation as a workaround for
https://github.com/gradle/gradle/issues/1135.
Issue #KT-28896 Fixed
This commit is contained in:
+11
-2
@@ -81,13 +81,22 @@ abstract class AbstractKotlinCompilation<T : KotlinCommonOptions>(
|
||||
commonSourceSet += sourceSet.kotlin
|
||||
}
|
||||
}
|
||||
// Note! Invocation of getByName results in preliminary task instantiation. After fix of this issue the following code should be uncommented:
|
||||
|
||||
// Note! Invocation of withType-all results in preliminary task instantiation.
|
||||
// After fix of this issue the following code should be uncommented:
|
||||
// if (useLazyTaskConfiguration) {
|
||||
// (target.project.tasks.named(compileKotlinTaskName) as TaskProvider<AbstractKotlinCompile<*>>).configure {
|
||||
// it.configureAction()
|
||||
// }
|
||||
// }
|
||||
(target.project.tasks.getByName(compileKotlinTaskName) as AbstractKotlinCompile<*>).configureAction()
|
||||
|
||||
target.project.tasks
|
||||
// To configure a task that may have not yet been created at this point, use 'withType-matching-all`:
|
||||
.withType(AbstractKotlinCompile::class.java)
|
||||
.matching { it.name == compileKotlinTaskName }
|
||||
.all { compileKotlinTask ->
|
||||
compileKotlinTask.configureAction()
|
||||
}
|
||||
}
|
||||
|
||||
override fun source(sourceSet: KotlinSourceSet) {
|
||||
|
||||
Reference in New Issue
Block a user