Jesse Wilson
01/29/2025, 3:05 AMJesse Wilson
01/29/2025, 3:07 AM@CacheableTask
abstract class MyTask @Inject constructor() : DefaultTask() {
@get:Input
abstract val inputJars: ListProperty<Provider<MinimalExternalModuleDependency>>
@get:OutputFile
abstract val output: RegularFileProperty
@TaskAction
fun execute() {
val configurationContainer = services.get<ConfigurationContainer>()
val configuration = configurationContainer.detachedConfiguration()
.apply {
isCanBeResolved = true
isTransitive = false
isCanBeConsumed = false
for (provider in inputJars.get()) {
dependencies.addLater(provider)
}
}
val files = configuration.files
// Use files to produce output
}
}
Jesse Wilson
01/29/2025, 3:09 AMbuild.gradle.kts
file:
val myTask by tasks.registering(MyTask::class) {
inputJars.addAll(
libs.myVeryLargeDependency,
libs.myOtherVeryLargeDependency,
)
output.set(layout.buildDirectory.file("myTask/output.txt"))
}
Jesse Wilson
01/29/2025, 3:10 AMConfigurationContainer
at execution time, with which I can create a new Configuration
Jesse Wilson
01/29/2025, 3:11 AMProvider<MinimalExternalModuleDependency>
doesn’t seem to interfere with the configuration cacheJesse Wilson
01/29/2025, 3:12 AMListProperty<Provider<MinimalExternalModuleDependency>>
instead of something normal like Property<FileCollection>
Jesse Wilson
01/29/2025, 3:12 AMdependencies {}
block hereJesse Wilson
01/29/2025, 3:13 AMJesse Wilson
01/29/2025, 3:13 AMThomas Broyer
01/29/2025, 8:35 AMVampire
01/29/2025, 3:28 PMProperty<FileCollection>
usually is not normal. 🙂
Normal is ConfigurableFileCollection
which is already a lazy construct.Jesse Wilson
01/30/2025, 2:23 PMJesse Wilson
01/30/2025, 2:38 PMResolution of the configuration :treehouse-build:upstream-protos:detachedConfiguration1 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behavior has been deprecated. This will fail with an error in Gradle 9.0. For more information, please refer to <https://docs.gradle.org/8.12.1/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors> in the Gradle documentation.
Vampire
01/30/2025, 2:53 PMservices
is not a good idea, it is in an internal package as well as the get
you use, and it (the getServices()
) returns a class in an internal package.
Just get it injected using
@get:Inject
abstract val configurations: ConfigurationContainer
Vampire
01/30/2025, 2:54 PMVampire
01/30/2025, 2:54 PMVampire
01/30/2025, 3:11 PMJesse Wilson
02/02/2025, 11:15 PM@get:Inject
is just what I needed. Thank you!Jesse Wilson
02/02/2025, 11:15 PMVampire
02/02/2025, 11:42 PM