在Gradle中:如何正确地将内置配置继承到新的自定义配置



当我试图用这个构建脚本进行测试运行时,它给了我一个错误:java.lang.UnsaisfiedLinkError,但如果我在这个dependencies块内将其从nativesOS更改为runtimeOnly时,它可以正常工作。

如果我继续这个构建脚本,我必须手动添加这个"applicationDefaultJvmArgs">并插入本机路径?如果可能的话,是否有其他方法可以将这个runtimeOnly配置正确地继承到新的配置中,而不是再次添加一些锅炉板功能?

val nativesOS : Configuration by configurations.creating {
this.isTransitive = false
this.extendsFrom(configurations.runtimeOnly.get())
}
dependencies {
implementation(platform("org.lwjgl:lwjgl-bom:3.2.3"))
...
// I want this one
nativesOS("org.lwjgl","lwjgl$lib", "3.2.3",  classifier = "natives-windows")
// I don't want this, cuz it's like losing the purpose of creating a new config, but never the less it works in the meantime.
// runtimeOnly("org.lwjgl","lwjgl$lib", "3.2.3",  classifier = "natives-windows")
// this is test kit I'm using, is this the reason I could run a test without the needs of
// modifying some args in JVM.
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
...
}
tasks.withType(Test::class) {
this.useJUnitPlatform()
}

注意:我添加了一个在本地窗口的依赖项中找到的显式版本,因为如果我提取/解压缩它,它将不起作用。出于某种原因,Platform/BOM文件在这种情况下不起作用。

我只需要交换它:

val nativesOS : Configuration by configurations.creating {
this.isTransitive = false
// from like this,
// this.extendsFrom(configurations.runtimeOnly.get())

// into like this,
configurations.runtimeOnly.get().extendsFrom(this)
}

然后进行另一次测试运行,这在这种情况/项目中不会出错。

最新更新