gpt4 book ai didi

gradle - 如何使用 Gradle 和 Kotlin DSL 创建额外的 Kotlin SourceSet

转载 作者:行者123 更新时间:2023-12-02 12:14:44 29 4
gpt4 key购买 nike

我想创建一个测试库源集,src/tlib/kotlin “位于”主要和测试之间。我有这个,但我不知道为什么要使用 java kotlin 的源目录,我需要根据我的主要来源获取它

sourceSets {
create("tlib").java.srcDir("src/tlib/kotlin")
}

更新
Calebs-MBP:phg-entity calebcushing$ ./gradlew build
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class phg.entity.AbstractEntityBase, unresolved supertypes: org.springframework.data.domain.Persistable
> Task :compileTlibKotlin FAILED

关闭
sourceSets {
val main by getting
val tlib by creating {
java {
srcDir("src/tlib/kotlin")
compileClasspath += main.output
runtimeClasspath += main.output
}
}
val test by getting {
java {
compileClasspath += tlib.output
runtimeClasspath += tlib.output
}
}
}

configurations {
val compile by getting
val runtime by getting
val tlibCompile by getting {
extendsFrom(compile)
}
val tlibRuntime by getting {
extendsFrom(runtime)
}
val testCompile by getting {
extendsFrom(tlibCompile)
}
val testRuntime by getting {
extendsFrom(tlibRuntime)
}
}

dependencies {
implementation("${project.group}:constant:[0.1,1.0)")
api("javax.validation:validation-api")
api("javax.persistence:javax.persistence-api")
api("org.springframework.data:spring-data-commons") // has the missing dependency

最佳答案

许多事情都由插件妥善处理,因此添加的内容实际上是关于配置 sourceSet 类路径和接线配置。

这是一个简短的回答,显示了类路径配置和一个配置扩展:

sourceSets {
val tlib by creating {
// The kotlin plugin will by default recognise Kotlin sources in src/tlib/kotlin
compileClasspath += sourceSets["main"].output
runtimeClasspath += sourceSets["main"].output
}
}

configurations {
val tlibImplementation by getting {
extendsFrom(configurations["implementation"])
}
}

关于gradle - 如何使用 Gradle 和 Kotlin DSL 创建额外的 Kotlin SourceSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55170974/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com