Slackbot
02/08/2024, 4:33 PMMartin
02/08/2024, 4:39 PMlistOf(
"dependency:notation:1.0",
"anotherDependency:notation:1.0",
).forEach {
configurations.getByName("configuration").dependencies.add(dependencies.create(provider { it }))
}
Martin
02/08/2024, 4:42 PMJakub Chrzanowski
02/08/2024, 4:48 PMdependenciesProvider
is actually:
val dependenciesProvider = providers.gradleProperty("dependencies").map { it.split(',') }
and in gradle.properties
:
dependencies=dependency:notation:1.0,anotherDependency:notation:1.0
This is still a way simpler case than mine, but the point is that my provider holds a list of dependencies, and I want to keep that resolved lazily.
Currently, I ended up with:
dependenciesProvider.get().forEach {
dependencies.add("configuration", it)
}
but that breaks the whole idea of providers.Adam
02/08/2024, 4:50 PMdependencies.addAllLater()
, but you have to map the dependencies, e.g.
dependencies.addAllLater(
dependenciesProvider.map { deps ->
deps.map { dep ->
project.dependencies.create("dep")
}
}
)
Adam
02/08/2024, 4:50 PMMartin
02/08/2024, 4:51 PMLater
suffix vs just addAll(Provider<Iterable<>>)
but +1 on thisJakub Chrzanowski
02/08/2024, 4:51 PMAdam
02/08/2024, 4:53 PMJakub Chrzanowski
02/08/2024, 4:53 PMaddAllLater
in DependencyHandler
.Adam
02/08/2024, 4:55 PMMartin
02/08/2024, 4:55 PMConfiguration.dependencies
Martin
02/08/2024, 4:58 PMconfigurations.getByName("foo").dependencies.addAllLater(
dependenciesProvider.map {
it.map { dependencies.create(it) }
}
)
Martin
02/08/2024, 4:59 PMJakub Chrzanowski
02/08/2024, 5:00 PMDependencyHandler
as a starting point. 🤷Jakub Chrzanowski
02/08/2024, 5:00 PMJakub Chrzanowski
02/08/2024, 5:01 PMids
provider isn’t retrieved, so there’s just .map{}
Jakub Chrzanowski
02/08/2024, 5:05 PMids.map {
it.forEach { id ->
bundledPlugin(id, configurationName, action)
}
}.get
but this looks bad. 🤷Martin
02/08/2024, 5:05 PMconfigurations
up thereMartin
02/08/2024, 5:06 PMDependencyHandler
?Martin
02/08/2024, 5:07 PMconfigurations.getByName(configurationName).dependencies.addAllLater(
ids.map { it.map { dependencies.create(it) } }
)
?Martin
02/08/2024, 5:07 PMaction
Martin
02/08/2024, 5:08 PMaddAllLater
doesn't have an action
paramterMartin
02/08/2024, 5:12 PMVampire
02/08/2024, 5:19 PMaddAllLater
does not have action
as it takes a Provider<Iterable<Dependency>>
.
The configuration action
would be where you create Dependency
.
Another option is to use configurations.getByName(configurationName).withDependencies { ... }
. It is more meant to for example last-minute add some dependencies based on already declared dependencies, but you could also do it there. It is executed last-minute right before the dependencies are going to be resolved.Jakub Chrzanowski
02/08/2024, 7:37 PMVampire
02/08/2024, 11:46 PMJakub Chrzanowski
02/09/2024, 7:33 AMconfigurations.getByName(configurationName).withDependencies {}
and
dependencies.addProvider(configurationName, ...)
in one class?Vampire
02/09/2024, 7:52 AM.withDependencies { add }
and dependencies.addAllLater
.Jakub Chrzanowski
02/09/2024, 8:02 AMdependencies.addAllLater
as .withDependencies { add }
simply doesn’t resolve providers.Vampire
02/09/2024, 8:34 AMconfigurations.getByName(configurationName).withDependencies {
addAll(ids.get().map { createIntelliJPlatformBundledPluginDependency(it).apply(action) })
}
or
configurations.getByName(configurationName).withDependencies {
ids.get().forEach { add(createIntelliJPlatformBundledPluginDependency(it).apply(action)) }
}
and
configurations.getByName(configurationName).dependencies.addAllLater(ids.map {
it.map { id ->
createIntelliJPlatformBundledPluginDependency(id).apply(action)
}
})
In withDependencies
there is not really a need to continue using providers.
This action is executed right before dependency resolution.
So using addLater
or addAllLater
within withDependencies
is imho unneccessary and just makes things a tad bit slower and the code more complex.