Slackbot
09/07/2022, 5:43 PMJendrik Johannes
09/08/2022, 6:39 AMtony
09/08/2022, 8:27 AMtony
09/09/2022, 4:01 AMCaused by: org.gradle.internal.execution.fingerprint.InputFingerprinter$InputFingerprintingException: Cannot fingerprint input property 'artifactIds': value '[junit-4.12.jar (junit:junit:4.12), hamcrest-core-1.3.jar ...
cannot be serialized.
...
Caused by: java.lang.ClassCastException: class org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier cannot be cast to class org.gradle.internal.component.external.model.ModuleComponentFileArtifactIdentifier (org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier and org.gradle.internal.component.external.model.ModuleComponentFileArtifactIdentifier are in unnamed module of loader org.gradle.initialization.MixInLegacyTypesClassLoader @638ef7ed)
at org.gradle.api.internal.artifacts.metadata.ModuleComponentFileArtifactIdentifierSerializer.write(ModuleComponentFileArtifactIdentifierSerializer.java:26)
at org.gradle.internal.snapshot.impl.AbstractValueProcessor.gradleSerialization(AbstractValueProcessor.java:160)
... 68 more
where my code looks like this:
@get:Input
abstract val artifactIds: ListProperty<ComponentArtifactIdentifier>
internal fun configureTask(
compileClasspath: Configuration,
runtimeClasspath: Configuration
) {
val extractor = IdExtractor()
artifactIds.addAll(compileClasspath.externalArtifactsFor("jar").resolvedArtifacts.map(extractor))
artifactIds.addAll(runtimeClasspath.externalArtifactsFor("jar").resolvedArtifacts.map(extractor))
}
internal fun Configuration.externalArtifactsFor(attrValue: String): ArtifactCollection = externalArtifactViewFor(attrValue).artifacts
private fun Configuration.externalArtifactViewFor(attrValue: String): ArtifactView = incoming.artifactView {
attributes.attribute(Attribute.of("artifactType", String::class.java), attrValue)
lenient(true)
componentFilter { id -> id is ModuleComponentIdentifier }
}
private class IdExtractor : Transformer<List<ComponentArtifactIdentifier>, Collection<ResolvedArtifactResult>> {
override fun transform(artifacts: Collection<ResolvedArtifactResult>): List<ComponentArtifactIdentifier> {
return artifacts.stream().map(ResolvedArtifactResult::getId).collect(Collectors.toList())
}
}
Note that I must use an ArtifactView
, because this is an Android project, and I have to tell Gradle which artifactType
I'm querying for or it cannot resolve the configuration. Not using an artifactView simply leads to a different error.Rodrigo Oliveira
09/09/2022, 2:27 PMplugins {
`java-library`
}
abstract class PrintIds : DefaultTask() {
@get:Input
abstract val artifactIds: ListProperty<ComponentArtifactIdentifier>
@TaskAction
fun printIds() {
artifactIds.orNull?.forEach {
println(it)
}
}
internal fun configureTask(
compileClasspath: Configuration,
runtimeClasspath: Configuration
) {
val extractor = IdExtractor()
artifactIds.addAll(compileClasspath.externalArtifactsFor("jar").resolvedArtifacts.map(extractor))
artifactIds.addAll(runtimeClasspath.externalArtifactsFor("jar").resolvedArtifacts.map(extractor))
}
internal fun Configuration.externalArtifactsFor(attrValue: String): ArtifactCollection =
externalArtifactViewFor(attrValue).artifacts
private fun Configuration.externalArtifactViewFor(attrValue: String): ArtifactView = incoming.artifactView {
attributes.attribute(Attribute.of("artifactType", String::class.java), attrValue)
lenient(true)
componentFilter { id -> id is ModuleComponentIdentifier }
}
private class IdExtractor : Transformer<List<ComponentArtifactIdentifier>, Collection<ResolvedArtifactResult>> {
override fun transform(artifacts: Collection<ResolvedArtifactResult>): List<ComponentArtifactIdentifier> {
return artifacts.map(ResolvedArtifactResult::getId)
}
}
}
dependencies {
implementation("junit:junit:4.12")
}
repositories {
mavenCentral()
}
tasks {
register<PrintIds>("printIds") {
configureTask(
configurations.compileClasspath.get(),
configurations.runtimeClasspath.get()
)
}
}
Rodrigo Oliveira
09/09/2022, 2:28 PMtony
09/09/2022, 10:01 PM./gradlew :funcTest --tests DuplicateDependencyVersionsSpec
and for good measure, here's a build scan showing the test failuretony
09/13/2022, 8:13 PMRodrigo Oliveira
09/13/2022, 8:14 PMRodrigo Oliveira
09/13/2022, 8:14 PMtony
09/13/2022, 8:16 PMRodrigo Oliveira
09/14/2022, 1:57 PM7.6-branch-bamboo_cc_release_ComponentArtifactIdentifier_ListProperty-20220914130118+0000
has the candidate fix.tony
09/14/2022, 5:37 PMRodrigo Oliveira
09/14/2022, 6:26 PMtony
09/14/2022, 8:20 PMRodrigo Oliveira
09/14/2022, 11:05 PMRodrigo Oliveira
09/14/2022, 11:06 PMtony
09/14/2022, 11:14 PM