找不到名称为 '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 发布脚本。
我在生成 .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 the
Android 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 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)
}
}
}
}
应用模块build.gradle
apply plugin: 'com.android.library'
apply from: rootProject.file('deploy-bintray.gradle.kts')
android {...}
deploy-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 the Android 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 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)
}
}
}
}