SoftwareComponentInternal with name 'java' not found.
GuilhE opened this issue · 2 comments
This is my setup:
Module: checks (java-library)
Module: styling-lint (android-library) which works like a bridge between checks and projects who implements styling-lint:
apply plugin: 'com.android.library'
apply from: rootProject.file('deploy-bintray.gradle.kts')
android {...}
dependencies { lintPublish project(':checks') }
deploy-bintray.gradle.kts it's my bintray/maven publications script. You can find the code here.
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())
...
}
}
}
it fails with:
SoftwareComponentInternal with name 'java' not found.
or, if I comment from(components["java"]) it fails with:
SourceSet with name 'main' not found.
If I add java plugin:
The 'java' plugin has been applied, but it is not compatible with the
Android plugins.
So I'm stuck here.
I believe the problem with the sources it's related to the fact that the android-library module has no code and it only imports the checks module by lintPublish project(':checks') }. This setup is desired because I want the lint jar created by checks to be "auto-imported" when other projects depend (implementation) on styling-lint project.
How can I solve this?
I've made some improvements. Regarding sourcesJar I've moved that function to the module build.gradle.kts and changed it to from(android.sourceSets.getByName("main").java.srcDirs) so the build.gradle became:
plugins {
id("com.android.library")
}
android {
compileSdkVersion(AndroidConstants.compileSdkVersions)
defaultConfig {
minSdkVersion(AndroidConstants.minSdkVersion)
targetSdkVersion(AndroidConstants.targetSdkVersion)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
/** Package the given lint checks library into this AAR */
lintPublish(project(":checks"))
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}
apply(from = rootProject.file("deploy-bintray.gradle.kts"))
This was the only way I found to avoid:
SourceSet with name 'main' not found.
Is it correct?
Next, I've updated deploy-bintray.gradle.kts to:
publications {
create<MavenPublication>(bintrayRepo) {
groupId = publishedGroupId
artifactId = artifact
version = libraryVersion
from(components["java"])
// artifact(sourcesJar.get())
artifact(tasks.findByName("sourcesJar"))
artifact(dokkaJar.get())
Unfortunately from(components["java"]) still fails...
The problem was not related to lintPublish configuration.
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.
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").
Last but not least, as stated here (step 7):
"Also, the POM file generated does not include the dependency chain so
it must be explicitly added..."
I had to add this:
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)
}
}
}
}