Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing Library using Kotlin DSL

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)
}
like image 280
Furkan Akdemir Avatar asked Oct 27 '22 08:10

Furkan Akdemir


1 Answers

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.

like image 194
dr0i Avatar answered Nov 15 '22 07:11

dr0i