I'm trying to refactor my plugin to use `configura...
# community-support
t
I'm trying to refactor my plugin to use
configurations.named()
instead of
configurations.getByName()
, and ran into an issue that ultimately looks like this:
Copy code
- Task `:lib:findNativeLibsDebug` of type `com.autonomousapps.tasks.FindNativeLibsTask`: cannot serialize object of type 'org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult', a subtype of 'org.gradle.api.artifacts.result.ArtifactResult', as these are not supported with the configuration cache.
  See <https://docs.gradle.org/8.11.1/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
I experimented and I no longer get that issue from Gradle 9.5.0. I'm looking at the release notes for that release, and there's nothing obviously related to this issue. The nearest thing I can see is https://github.com/gradle/gradle/issues/35318. What am I missing? Is my code only working in newer releases by accident? I think this is from this in my task:
Copy code
@get:Internal
public abstract val androidJni: SetProperty<ResolvedArtifactResult>

@Optional // Only available on Android
@PathSensitive(PathSensitivity.RELATIVE)
@InputFiles
public fun getAndroidJniFiles(): Provider<List<File>>? {
  if (!androidJni.isPresent) return null
  return androidJni.map { artifactResults -> artifactResults.map { it.file } }
}

@Input
public fun getAndroidJniIdentifiers(): Provider<List<String>> = androidJni.identifiers()
✅ 1
p
Just use the androidJni/ResolvedArtifactResult as Input and not the files
t
I thought that's what the error was saying? that a
(Default)ResolvedArtifactResult
can't be a CC input
p
Ahh, you are right: https://docs.gradle.org/current/userguide/artifact_resolution.html#sec:resolving_artifacts I used it in licensee but I also mapped the files as input
t
ah I see, these use
Provider.zip
to reattach the artifact metadata to the files. That's such an annoying thing to have to do. I guess it's fixed in 9.5.0? But again, I don't see it in the release notes 😔
lol that approach made no difference. Still doesn't work for earlier versions of Gradle 🪦
Copy code
> Cannot fingerprint input property 'androidJniDetails': value '[ArtifactDetails(id=graphics-core-1.0.2.aar -> jni (androidx.graphics:graphics-core:1.0.2), variant=androidx.graphics:graphics-core:1.0.2 variant releaseVariantReleaseApiPublication)]' cannot be serialized.
oh nm, I was able to use
@Nested
Copy code
public data class ArtifactDetails(
  @get:Input val id: ComponentArtifactIdentifier,
  @get:Input val variant: ResolvedVariantResult,
)
Gradle docs considered harmful
m
We've made a few more of dependency resolution types CC-compatible in 9.x. AFAIR,
ResolvedArtifactResult
is one of them (maybe except one or two very rare subtypes).
👍 1
t
something about this approach is breaking task attribution. I don't get it. I'm getting this old problem:
Copy code
* What went wrong:
A problem was found with the configuration of task ':lib_android:artifactsReportDebug' (type 'ArtifactsReportTask').
Property has implicit dependency
  Gradle detected a problem with the following location: '.../dependency-analysis-gradle-plugin/build/functionalTest/AdviceFilterProject-665aa936-10/java-annotations/build/classes/java/main'
    Task ':lib_android:artifactsReportDebug' uses this output of task ':java-annotations:compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed
I've gone from this (in my task definition):
Copy code
private lateinit var classpath: ArtifactCollection

public fun setClasspath(artifacts: ArtifactCollection) {
  this.classpath = artifacts
  classpathIdentifiers.set(artifacts.identifiers())
}

@Classpath
public fun getClasspath(): FileCollection = classpath.artifactFiles

@get:Input
public abstract val classpathIdentifiers: ListProperty<String>
to this:
Copy code
@get:Nested
  public abstract val classpathDetails: ListProperty<ArtifactDetails>

  @get:Classpath
  public abstract val classpathFiles: ListProperty<File>

  internal fun withClasspath(artifacts: Provider<Set<ResolvedArtifactResult>>) {
    classpathDetails.set(ArtifactDetails.of(artifacts))
    classpathFiles.set(ArtifactDetails.files(artifacts))
  }
and the latter is what's recommended in the gradle docs. `ArtifactDetails`:
Copy code
public data class ArtifactDetails(
  @get:Input val id: ComponentArtifactIdentifier,
  @get:Input val variant: ResolvedVariantResult,
) {
  internal companion object {
    fun of(artifacts: Provider<Set<ResolvedArtifactResult>>): Provider<List<ArtifactDetails>> {
      return artifacts.map { it.map { artifact -> ArtifactDetails(artifact.id, artifact.variant) } }
    }

    fun files(artifacts: Provider<Set<ResolvedArtifactResult>>): Provider<List<File>> {
      return artifacts.map { it.map { artifact -> artifact.file } }
    }
  }
}
is there a recommended approach to debugging task attribution issues? does
--info
or
--debug
show relevant information?
🦆 so in the before case, the build scan shows the task attribution
and now in the after case, the scan shows a critical difference
one thing I forgot to mention here is that my change doesn't even involve the
artifactsReport
task. It was a different task, and now somehow I've lost attribution in this task
@Mikhail Lopatkin do you have any ideas how I could debug this?
apparently it's a limitation with
@Nested
inputs built from providers. I'm going to remove all these nested inputs