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,104 @@ 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+ outputDirectory.set(layout.buildDirectory.dir(" dokka/html" ))
155+ }
156+ }
157+ }
158+
159+ val dokkaGenerateJavadocJar by tasks.registering(Jar ::class ) {
160+ group = " dokka"
161+ dependsOn(tasks.dokkaGeneratePublicationJavadoc)
162+ from(tasks.dokkaGeneratePublicationJavadoc.flatMap { it.outputDirectory })
163+ archiveClassifier.set(" javadoc" )
164+ description = " Assembles a JAR containing the Javadoc-style documentation generated by Dokka."
165+ }
166+
167+ val dokkaGenerateHtmlJar by tasks.registering(Jar ::class ) {
168+ group = " dokka"
169+ dependsOn(tasks.dokkaGeneratePublicationHtml)
170+ from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
171+ archiveClassifier.set(" html-docs" )
172+ description = " Assembles a JAR containing the HTML documentation generated by Dokka."
173+ }
174+
175+ val dokkaCleanJavadoc by tasks.registering(Delete ::class ) {
176+ group = " dokka"
177+ delete = setOf (project.file(" build/dokka/javadoc" ))
178+ description = " It removes the documentation generated by Dokka."
179+ }
180+
181+ val dokkaCleanHtml by tasks.registering(Delete ::class ) {
182+ group = " dokka"
183+ delete = setOf (project.file(" build/dokka/html" ))
184+ description = " It removes the documentation generated by Dokka."
185+ }
186+
187+ // tasks.dokkaGeneratePublicationJavadoc.dependsOn(dokkaCleanJavadoc)
188+ // tasks.dokkaGeneratePublicationHtml.dependsOn(dokkaCleanHtml)
189+
190+ val dokkaClean by tasks.registering {
191+ group = " dokka"
192+ dependsOn(dokkaCleanJavadoc, dokkaCleanHtml)
193+ }
194+
195+ val sourcesJar by tasks.registering(Jar ::class ) {
196+ archiveClassifier.set(" sources" )
197+ from(project.file(" src/main/java" ))
198+ }
199+
200+ // Gradle 9.1 deprecation fix
201+ configurations {
202+ @Suppress(" UnstableApiUsage" )
203+ consumable(" jars" ) {
204+ outgoing.artifact(dokkaGenerateJavadocJar)
205+ outgoing.artifact(sourcesJar)
206+ }
207+ }
208+
209+ tasks.named(" assemble" ) {
210+ dependsOn(dokkaGenerateJavadocJar)
211+ dependsOn(sourcesJar)
109212}
110213
111214group = " io.syslogic"
0 commit comments