<@U0BRK9HC5> Following discussion here: <https://k...
# gradle
a
@gildor Following discussion here: https://kotlinlang.slack.com/archives/C0922A726/p1714378209726859?thread_ts=1709819179.013749&amp;cid=C0922A726 Just encountered a problem (in C++) that is easily solved with gradle, but requires a lot of work in a custom language like CMake. I need to automatically unzip an archive with C++ dependencies on build (our git just does not work well with that amount of junk and dependency management is not available).
g
I do agree, we have the same issue with C++ infrastructure (to get C++ pre-built dependencies for our C++ libs, published as an Android library). Currently our solution is to reuse dependencies API of gradle with custom configuration, so far it was the best one, super easy to implement, is not affected by ./gradlew clean, do not pollute build cache Considering that there is no standard for this on C++ (or C++ + JVM), I don't see that it can be done in general way, but it looks that for this it is work for a custom plugin. And if reusing gradle custom configuration works (I don't see why it wouldn't), it's actually pretty easy to implement even with current prototype of Declarative Gradle, which supports custom dependencies block (for any dependencies, depending on implementation, so I see it like:
Copy code
nativeBuild {
     dependencies {
            cppSource("some:dep:1.0@zip")
      }
}
Even without Declarative Gradle, it looks like a thing, which should be handled on plugin level, not on level of build files
👍 1
a
Indeed. If it is a frequent case. But it is a pain, when you need this only for one project.
g
But even for one project, it can be just a convention plugin for it, implementation is pretty straight forward:
Copy code
val cppSourcesConfiguration = project.configurations.register("cppSources") {
      isCanBeResolved = true
      isCanBeDeclared = true
}

val resolveCoursesTaskProvider = project.tasks.register<Copy>("resolveCppSources") {
            from(cppSourcesConfiguration.get().map(project::tarTree))
            into(project.layout.buildDirectory.dir("target/dir"))
}

project.plugins.withType<BasePlugin>().configureEach {
            project.tasks.named("preBuild") {
                dependsOn(resolveCoursesTaskProvider)
            }
        }
Additionally, it requires custom repo from where it downloaded (if your repo doesn't follow Maven convention, you can use Ivy, it allows custom convention), but maven would be the easiest one And to use, something like:
Copy code
dependencies {
   cppSources("my:dep:1.0@tgz")
}
My point, that we have to do such stuff for single repo if it uses something not-standard like in this case I just suggest to even for this always use convention plugin instead hack it on build file