找不到名称为"java"的SoftwareComponentInternal [英] SoftwareComponentInternal with name 'java' not found
问题描述
应用模块build.gradle
apply plugin: 'com.android.library'
apply from: rootProject.file('deploy-bintray.gradle.kts')
android {...}
deploy-bintray.gradle.kts ,这是我的bintray/maven出版物脚本.
deploy-bintray.gradle.kts it's my bintray/maven publications script.
我在生成.jar文件时遇到问题:
I'm having problems generating .jar files:
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())
...
}
}
}
它失败并显示:
找不到名称为"java"的SoftwareComponentInternal.
SoftwareComponentInternal with name 'java' not found.
或者,如果我评论from(components["java"])
,它将失败,并显示以下信息:
or, if I comment from(components["java"])
it fails with:
找不到名称为"main"的SourceSet.
SourceSet with name 'main' not found.
如果我添加Java插件:
If I add java plugin:
已应用了"java"插件,但与 Android插件.
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
所以我被困在这里.我该如何解决?
So I'm stuck here. How can I solve this?
推荐答案
我终于找到了解决方案!
我做错了一些事情,首先, dokkaJar 和 sourceJar 任务都必须在主build.gradle
中,而不是在deploy-bintray.gradle.kts
中.移动它们可以使其工作并修复:
I finally found a solution!
I was doing a few things wrong, first, both dokkaJar and sourceJar tasks have to be in the main build.gradle
and not inside deploy-bintray.gradle.kts
. Moving them made it work and fixes:
SourceSet with name 'main' not found.
第二,我们不能使用from(components["java"])
,因为这是一个Android库,因此我已将该行替换为artifact("$buildDir/outputs/aar/${artifactId}-release.aar")
.
Secondly we cannot use from(components["java"])
because this is an Android lib so I've replaced that line with artifact("$buildDir/outputs/aar/${artifactId}-release.aar")
.
最后但并非最不重要,如此处(第7步)所述:>
Last but not least, as stated here (step 7):
"而且,生成的POM文件不包括依赖项链,因此 必须将其明确添加..."
"Also, the POM file generated does not include the dependency chain so it 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)
}
}
}
}
这篇关于找不到名称为"java"的SoftwareComponentInternal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!