gpt4 book ai didi

gradle - 未找到名称为 'java' 的 SoftwareComponentInternal

转载 作者:行者123 更新时间:2023-12-03 02:53:17 32 4
gpt4 key购买 nike

应用模块build.gradle

apply plugin: 'com.android.library'
apply from: rootProject.file('deploy-bintray.gradle.kts')
android {...}
部署-bintray.gradle.kts 这是我的 bintray/maven 出版物脚本。
我在生成 .jar 文件时遇到问题:
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(project.the<SourceSetContainer>()["main"].allSource)
}

publications {
create<MavenPublication>(bintrayRepo) {
groupId = publishedGroupId
artifactId = artifact
version = libraryVersion

from(components["java"])
artifact(sourcesJar.get())
artifact(dokkaJar.get())
...
}
}
}
它失败了:

SoftwareComponentInternal with name 'java' not found.


或者,如果我评论 from(components["java"])它失败了:

SourceSet with name 'main' not found.


如果我添加 java 插件:

The 'java' plugin has been applied, but it is not compatible with theAndroid plugins.


所以我被困在这里。我该如何解决这个问题?

最佳答案

我终于找到了解决办法!
我做错了一些事情,首先,dokkaJar 和 sourceJar 任务都必须在主 build.gradle而不是在deploy-bintray.gradle.kts .移动它们使其工作并修复:

SourceSet with name 'main' not found.


其次我们不能使用 from(components["java"])因为这是一个 Android 库,所以我用 artifact("$buildDir/outputs/aar/${artifactId}-release.aar") 替换了该行.
最后但同样重要的是,如 here (step 7) 所述:

"Also, the POM file generated does not include the dependency chain soit must be explicitly added..."


我不得不添加这个:
pom {
...
withXml {
val dependenciesNode = asNode().appendNode("dependencies")
configurations.getByName("implementation") {
dependencies.forEach {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.group)
dependencyNode.appendNode("artifactId", it.name)
dependencyNode.appendNode("version", it.version)
}
}
}
}

关于gradle - 未找到名称为 'java' 的 SoftwareComponentInternal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62982138/

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