以下示例代码来自OpenAI API Kotlin客户端项目。
您可以在https://github.com/aallam/openai-kotlin/tree/main/sample/native查看它
我在Android Studio中打开了示例代码,但找不到作者定义implementation(projects.openaiClient)
的地方,我已经搜索了整个项目,你能告诉我吗?
build.gradle.kts
plugins { kotlin("multiplatform")}kotlin { val hostOs = System.getProperty("os.name") val isMingwX64 = hostOs.startsWith("Windows") val nativeTarget = when { hostOs == "Mac OS X" -> macosX64("native") hostOs == "Linux" -> linuxX64("native") isMingwX64 -> mingwX64("native") else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } nativeTarget.apply { binaries { executable { entryPoint = "main" } } } sourceSets { val nativeMain by getting { dependencies { //implementation("com.aallam.openai:openai-client:<version>") implementation(projects.openaiClient) // projects.openaiClient在哪里 implementation(libs.ktor.client.curl) // libs.ktor.client.curl在哪里 } } }}
回答:
openai-client
子项目位于这里。在settings.gradle.kts
中添加了包含设置。
在示例代码中,作者使用了一种称为类型安全项目访问器的东西:
带有连字符案例(some-lib)或蛇形案例(some_lib)的项目名称将在访问器中转换为驼峰案例:projects.someLib。
这意味着可以使用projects.openaiClient
来添加依赖项。