This message was deleted.
# community-support
s
This message was deleted.
1
m
Something like this?
Copy code
listOf(
  "dependency:notation:1.0",
  "anotherDependency:notation:1.0",
).forEach {
  configurations.getByName("configuration").dependencies.add(dependencies.create(provider { it }))
}
Note that if your dependencies are a "g:a :v" string, I don't think adding them in providers changes much? Using non-lazy APIs would work similarly?
j
The point is that my
dependenciesProvider
is actually:
Copy code
val dependenciesProvider = providers.gradleProperty("dependencies").map { it.split(',') }
and in
gradle.properties
:
Copy code
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:
Copy code
dependenciesProvider.get().forEach {
  dependencies.add("configuration", it)
}
but that breaks the whole idea of providers.
a
you can use
dependencies.addAllLater()
, but you have to map the dependencies, e.g.
Copy code
dependencies.addAllLater(
  dependenciesProvider.map { deps ->
    deps.map { dep -> 
      project.dependencies.create("dep")
    }
  }
)
👍 1
☝️ 1
m
I'm curious why the
Later
suffix vs just
addAll(Provider<Iterable<>>)
but +1 on this
j
Dang, I’ve been using that already few months ago. 🤦‍♂️ Thanks, Adam!
a
my pleasure!
j
Oh, but there’s no
addAllLater
in
DependencyHandler
.
a
uh oh...
m
It's on
Configuration.dependencies
So I guess something like so?
Copy code
configurations.getByName("foo").dependencies.addAllLater(
  dependenciesProvider.map {
    it.map { dependencies.create(it) }
  }
)
(it's not red in my IDE but I have no idea if it actually works 😄 )
j
I can’t go another way — it’s all done having
DependencyHandler
as a starting point. 🤷
And this code actually doesn’t work as the
ids
provider isn’t retrieved, so there’s just
.map{}
I could
Copy code
ids.map {
    it.forEach { id ->
        bundledPlugin(id, configurationName, action)
    }
}.get
but this looks bad. 🤷
m
Looks like you have the
configurations
up there
So you could do without the
DependencyHandler
?
Copy code
configurations.getByName(configurationName).dependencies.addAllLater(
            ids.map { it.map { dependencies.create(it) } }
        )
?
modulo
action
Mmmm,
addAllLater
doesn't have an
action
paramter
But I never know when those are called. Maybe you can call it manually
v
addAllLater
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.
j
Awesome, this did the job — a sudden issue was resolved in a pretty nice way. https://github.com/JetBrains/gradle-intellij-plugin/blob/071da761e66f6b9db4270523d[…]form/gradle/extensions/IntelliJPlatformDependenciesExtension.kt Thank you, everyone! 🙇 🙌
🙌 1
🚀 1
v
Why did you mix both approaches?
j
You mean
Copy code
configurations.getByName(configurationName).withDependencies {}
and
Copy code
dependencies.addProvider(configurationName, ...)
in one class?
v
No,
.withDependencies { add }
and
dependencies.addAllLater
.
j
Apparently, I need to use
dependencies.addAllLater
as
.withDependencies { add }
simply doesn’t resolve providers.
v
The two approaches I mean are
Copy code
configurations.getByName(configurationName).withDependencies {
    addAll(ids.get().map { createIntelliJPlatformBundledPluginDependency(it).apply(action) })
}
or
Copy code
configurations.getByName(configurationName).withDependencies {
    ids.get().forEach { add(createIntelliJPlatformBundledPluginDependency(it).apply(action)) }
}
and
Copy code
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.