Publishing Library using Kotlin DSL
Asked Answered
M

1

6

I want to publish an Android library using Kotlin DSL. I got some errors

val sourcesJar by tasks.registering(Jar::class) {
    archiveClassifier.set("sources")
    from(sourceSets.getByName("main").allSource) 
}

SourceSet with name 'main' not found.

publishing {
    publications {
        create<MavenPublication>("maven") {
            groupId = artifactGroup
            artifactId = artifactID
            version = artifactVersion

            from(components["java"])
            artifact(sourcesJar.get())

            pom {
                ...
            }
        }
    }
}

SoftwareComponentInternal with name 'java' not found.

These blocks are in the library module build.gradle.kts.
Gradle Version: 5.6.2

How can I solve these problems ?

Thanks in advance.

UPDATE

Need to use android source sets.

val androidSourcesJar by tasks.registering(Jar::class) {
    archiveClassifier.set("sources")
    from(android.sourceSets.getByName("main").java.srcDirs)
}
Mediaeval answered 21/9, 2019 at 23:38 Comment(3)
Did you find a solution? I'm exactly in the same situation as youPutandtake
@Putandtake I updated my question.Mediaeval
That doesn't solve it for meAbott
L
2

I had to apply the java plugin apply plugin: "java", resp. add it like:

plugins {
 id 'java'

Get more infos around SoftwareComponent in the official gradle docs.

Literati answered 12/11, 2019 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.