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)
}