SoftwareComponentInternal with name 'java' not found
Asked Answered
H

2

6

App module build.gradle

apply plugin: 'com.android.library'
apply from: rootProject.file('deploy-bintray.gradle.kts')
android {...}

deploy-bintray.gradle.kts it's my bintray/maven publications script.

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. How can I solve this?

Heyday answered 19/7, 2020 at 15:18 Comment(4)
I'm stuck with this too.Tripetalous
Can't find help about this anywhere...Heyday
@Tripetalous I've found a solutionHeyday
I’ll try it. ThanksTripetalous
H
12

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)
         }
       }     
    }       
}
Heyday answered 11/9, 2020 at 8:20 Comment(0)
R
4

Don't use from(components["java"]), right code like this:

create<MavenPublication>("ReleaseAar") {
    groupId = "com.example"
    artifactId = "lib-git-repository"
    version = "1.0.0-SNAPSHOT"
    afterEvaluate { artifact(tasks.getByName("bundleReleaseAar")) 
}
Reside answered 12/5, 2023 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.