What would be a good Gradle way of achieving this?...
# community-support
a
What would be a good Gradle way of achieving this? • Download a dependency. • Based on the contents of the dependency and runtime arguments, dynamically compute the URLs of some additional required files. • Download the additional dependencies using Gradle (e.g. add a them to a Configuration, and add an Ivy repo with a suitable pattern). Context: I want to compile C code for use by Kotlin Native programs without using KGP. So I need to install
org.jetbrains.kotlin:kotlin-native-prebuilt
(which is simple - just pick the right OS-Arch variant, download and unpack), and the also the required dependencies (which is more complicated). Each
kotlin-native-prebuilt
archive contains a
konan.properties
file, that (among other things), can be processed to produce the URLs of required dependencies per Kotlin Native target, e.g.
<https://download.jetbrains.com/kotlin/native/resources/llvm/16.0.0-aarch64-macos/llvm-16.0.0-aarch64-macos-dev-63.tar.gz>
. The current download dependencies utility (
org.jetbrains.kotlin:kotlin-native-utils
) is slow, doesn't cache downloads, and is hard to customise. Options: • I see ComponentMetadataRules can add variants, and the variant can have custom files, and the URLs of the files can be explicitly specified. However, a CMR can't read files, so I can't see how to compute the dependencies from
konan.properties
. • Maybe it's possible to compute the necessary files in prior step and add them as arguments to the CMR? But I don't think that would be possible - the phases are out of order. • I want to avoid Artifact Transforms because they're too sensitive to classpath changes. Re-running when there's any change would be very slow.
v
I'm not sure there is a really clean way. Whatever you do - especially if you target configuration cache compatibility - you have to configure the repositories and dependencies at configuration time. So I guess you need to download the
kotlin-native-prebuilt
at configuration time, investigate it and then do the according configuration. You probably can use a detached configuration or a dedicated named configuration to download the file with caching at configuration time and then derive the configuration you need from it. But I never tried doing something like that.