11import com.android.build.api.dsl.LibraryExtension
2- import org.gradle.kotlin.dsl.assign
32import org.jetbrains.kotlin.gradle.dsl.JvmTarget
43
54// Module :library
@@ -8,6 +7,8 @@ plugins {
87 alias(libs.plugins.kotlin.compose.compiler)
98 alias(libs.plugins.builtin.kotlin)
109 alias(libs.plugins.legacy.kapt)
10+ alias(libs.plugins.dokka.html)
11+ alias(libs.plugins.dokka.javadoc)
1112 id(" maven-publish" )
1213}
1314
@@ -22,6 +23,10 @@ kotlin {
2223 }
2324}
2425
26+ kapt {
27+ generateStubs = true
28+ }
29+
2530composeCompiler {
2631 reportsDestination = layout.buildDirectory.dir(" compose_compiler" )
2732}
@@ -55,7 +60,7 @@ configure<LibraryExtension> {
5560
5661 buildTypes {
5762 debug {
58- // it breaks the data-binding, eg . when running ./gradlew :library:publishToMavenLocal
63+ // it breaks the data-binding, e.g . when running ./gradlew :library:publishToMavenLocal
5964 enableAndroidTestCoverage = false
6065 isMinifyEnabled = false
6166 }
@@ -106,6 +111,110 @@ dependencies {
106111
107112 /* Composable Preview */
108113 debugImplementation(libs.bundles.androidx.compose.tooling)
114+
115+ dokkaPlugin(libs.dokka.android.documentation.plugin)
116+ }
117+
118+ // Dokka generation
119+ dokka {
120+
121+ dokkaSourceSets.create(" main" ) {
122+
123+ val sdkComponents = androidComponents::sdkComponents.get()
124+ val sdkDirectory: Directory ? = sdkComponents.sdkDirectory.get()
125+ val compileSdk = project.extensions.getByType<LibraryExtension >().compileSdk
126+
127+ sourceRoots.from(
128+ files(File (" ${sdkDirectory} /platforms/${compileSdk} /android.jar" )),
129+ " ${projectDir.absolutePath} /src/main/java"
130+ )
131+
132+ sourceLink {
133+ localDirectory.set(file(" src/main/java" ))
134+ remoteUrl(" https://github.com/syslogic/androidx-colorpicker/tree/master/compose/src/main/java" )
135+ remoteLineSuffix.set(" #L" )
136+ }
137+ }
138+
139+ dokkaSourceSets.configureEach {
140+
141+ enableJdkDocumentationLink.set(true )
142+ enableKotlinStdLibDocumentationLink.set(true )
143+ enableAndroidDocumentationLink.set(true )
144+ jdkVersion.set(17 )
145+
146+ dokkaPublications.javadoc {
147+ moduleName.set(project.name)
148+ moduleVersion.set(project.version.toString())
149+ outputDirectory.set(layout.buildDirectory.dir(" dokka/javadoc" ))
150+ }
151+ dokkaPublications.html {
152+ moduleName.set(project.name)
153+ moduleVersion.set(project.version.toString())
154+ // sourceRoots = fileTree(project.fileTree("src/main/java"))
155+ outputDirectory.set(layout.buildDirectory.dir(" dokka/html" ))
156+ }
157+
158+ // externalDocumentationLinks.register("android") {
159+ // url("https://developer.android.com/reference")
160+ // packageListUrl("https://developer.android.com/reference/kotlin/package-list")
161+ // }
162+ }
163+ }
164+
165+ val dokkaGenerateJavadocJar by tasks.registering(Jar ::class ) {
166+ group = " dokka"
167+ dependsOn(tasks.dokkaGeneratePublicationJavadoc)
168+ from(tasks.dokkaGeneratePublicationJavadoc.flatMap { it.outputDirectory })
169+ archiveClassifier.set(" javadoc" )
170+ description = " Assembles a JAR containing the Javadoc-style documentation generated by Dokka."
171+ }
172+
173+ val dokkaGenerateHtmlJar by tasks.registering(Jar ::class ) {
174+ group = " dokka"
175+ dependsOn(tasks.dokkaGeneratePublicationHtml)
176+ from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
177+ archiveClassifier.set(" html-docs" )
178+ description = " Assembles a JAR containing the HTML documentation generated by Dokka."
179+ }
180+
181+ val dokkaCleanJavadoc by tasks.registering(Delete ::class ) {
182+ group = " dokka"
183+ delete = setOf (project.file(" build/dokka/javadoc" ))
184+ description = " It removes the documentation generated by Dokka."
185+ }
186+
187+ val dokkaCleanHtml by tasks.registering(Delete ::class ) {
188+ group = " dokka"
189+ delete = setOf (project.file(" build/dokka/html" ))
190+ description = " It removes the documentation generated by Dokka."
191+ }
192+
193+ // tasks.dokkaGeneratePublicationJavadoc.dependsOn(dokkaCleanJavadoc)
194+ // tasks.dokkaGeneratePublicationHtml.dependsOn(dokkaCleanHtml)
195+
196+ val dokkaClean by tasks.registering {
197+ group = " dokka"
198+ dependsOn(dokkaCleanJavadoc, dokkaCleanHtml)
199+ }
200+
201+ val sourcesJar by tasks.registering(Jar ::class ) {
202+ archiveClassifier.set(" sources" )
203+ from(project.file(" src/main/java" ))
204+ }
205+
206+ // Gradle 9.1 deprecation fix
207+ configurations {
208+ @Suppress(" UnstableApiUsage" )
209+ consumable(" jars" ) {
210+ outgoing.artifact(dokkaGenerateJavadocJar)
211+ outgoing.artifact(sourcesJar)
212+ }
213+ }
214+
215+ tasks.named(" assemble" ) {
216+ dependsOn(dokkaGenerateJavadocJar)
217+ dependsOn(sourcesJar)
109218}
110219
111220group = " io.syslogic"
0 commit comments