Skip to content

Instantly share code, notes, and snippets.

@autonomousapps
Created October 28, 2020 19:14
Show Gist options
  • Save autonomousapps/11fedf4b84c161f3a4a9e3c4274b6c32 to your computer and use it in GitHub Desktop.
Save autonomousapps/11fedf4b84c161f3a4a9e3c4274b6c32 to your computer and use it in GitHub Desktop.
configuration resolution
https://scans.gradle.com/s/h3lttvotbd7ve
failure:
```
Could not resolve all files for configuration ':app:labDebugAndroidTestCompileClasspath'.
> Failed to transform tguard.jar (project :tguard) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=8, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.localToProject=public, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for IdentityTransform: /Users/trobalik/workspace/hiya/aegis-android/tguard/build/libs/tguard.jar.
> Expecting a file or a directory: /Users/trobalik/workspace/hiya/aegis-android/tguard/build/libs/tguard.jar
```
```kotlin
project.configurations.flatMap { conf ->
// javadoc explicitly says conf.dependencies does not resolve the configuration
conf.dependencies.map { dep ->
// convert each dep to a string representation, like ":tguard" or "com.squareup.moshi:moshi:1.9.2"
}
}
```
for the inner bit, that is
```kotlin
internal fun Dependency.toIdentifier(): String? = when (this) {
is ProjectDependency -> {
val identifier = dependencyProject.path
if (isJavaPlatform()) // do something
identifier
}
is ModuleDependency -> {
// flat JAR/AAR files have no group.
val identifier = if (group != null) "${group}:${name}" else name
if (isJavaPlatform()) // do something
identifier
}
is FileCollectionDependency -> {
with(files.files) {
// note that this will ignore any flat file dep beyond the first
if (isNotEmpty()) first().name else null
}
}
// Don't have enough information, so ignore it
is SelfResolvingDependency -> null
else -> throw GradleException("Unknown Dependency subtype: \n$this\n${javaClass.name}")
}
```
and finally
```kotlin
private fun Dependency.isJavaPlatform(): Boolean = when (this) {
is ProjectDependency -> {
dependencyProject.pluginManager.hasPlugin("java-platform")
}
is ModuleDependency -> {
val category = attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)
category?.name == Category.REGULAR_PLATFORM || category?.name == Category.ENFORCED_PLATFORM
}
else -> throw GradleException("Unknown Dependency subtype: \n$this\n${javaClass.name}")
}
```
@autonomousapps
Copy link
Author

the :tguard project is a pure Kotlin-JVM project, no Android, and not java-library either. :app is a standard Android application project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment