somewhat related question to the above. For years ...
# dependency-management
t
somewhat related question to the above. For years now, I've known it to be Evil ™️ to resolve dependencies during configuration. However, I only recently noticed this in a build scan. This differentiates between user- and gradle-initiated resolution. Is the latter "ok"? Or am I doing it wrong? Code snippet in thread
Copy code
val artifacts = configurations
  .getByName("compileClasspath")
  .artifactsFor("jar")
tasks.register<ResolveDependenciesTask>("resolveDependencies") {
  setCompileClasspath(artifacts)
}
where
artifactsFor()
is defined as:
Copy code
private fun Configuration.artifactsFor(attrValue: String): ArtifactCollection = incoming
  .artifactViewFor(attrValue)
  .artifacts

private fun ResolvableDependencies.artifactViewFor(attrValue: String): ArtifactView = artifactView {
  it.attributes.attribute(attributeKey, attrValue)
  it.lenient(true)
  it.componentFilter { componentIdentifier ->
    componentIdentifier is ModuleComponentIdentifier
  }
}
note this is necessary because I'm dealing with an Android project
simply configuring that task resolves dependencies (by gradle)
t
I suppose this is because you're calling
.artifacts
on your artifact view at configuration time. How about doing that in a provider you pass to
setCompileClasspath
instead? (such that it's only resolved at execution time)
👍 1
t
If I use
provider { artifactView.artifacts.artifactFiles }
, I still see this, which does look like it's resolving the dependencies at configuration time. What am I missing?
no matter what I try, it really wants to resolve these dependencies during configuration 😞