How to declare a dependency to a native subproject form a Java project

I’m setting up a project that relies on native code written in both C and swift. Which is more or less shaped this way :

├── cpp-subproject
│   └── build.gradle.kts
├── java-library
│   └── build.gradle.kts
├── swift-subproject
│   └── build.gradle.kts
├── build.gradle.kts
└── settings.gradle.kts

I’d like to use the native library (.dylib / .so) produced in cpp-subproject and swift-subproject as dependency to java-library.

For now I’m using a dumb approach using a relative path. But I would like to use something using the Gradle API. E.g.

dependencies {
  api(project(":cpp-subproject"))
  api(project(":swift-subproject"))
}

Thank in advance for any advise.


For reference I tried to depend on the task project(":swift-subproject").tasks.named("linkRelease") but gradle is not happy because it doesn’t find the linkRelease task.

And I didn’t yet look at getting the cpp library yet.