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)
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With