Comments (12)
@dimsuz Here's an example:
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = javadoc.destinationDir
inputs.dir 'src/main/kotlin'
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
from dokka.
For me it was not obvious, who can come in handy. In order to generate javadoc.jar with dokka for android, write the following:
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from "$buildDir/javadoc"
}
from dokka.
For Gradle 7, I think a different approach is necessary. This is what I did:
// build.gradle.kts
plugins {
kotlin("jvm") version "1.5.31" // or whatever
id("org.jetbrains.dokka") version "1.5.31" // or whatever
`maven-publish`
}
java {
withJavadocJar()
}
// This task is added by Gradle when we use java.withJavadocJar()
val javadocJar = tasks.named<Jar>("javadocJar") {
from(tasks.named("dokkaJavadoc"))
}
publishing {
publications {
create<MavenPublication>("my-library") {
from(components["java"])
}
}
}
This takes advantage of Gradle's built-in wiring with java.withJavadocJar()
, which is important if you want the gradle module metadata (.module
file, cf pom.xml
) to include information on your documentation.
from dokka.
Thanks y'all. In a multi-module project with Kotlin DSL, it worked for me like this to publish with Javadoc JAR to Maven:
subprojects {
//...
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "maven-publish")
//...
tasks {
val sourcesJar by registering(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadocJar by registering(Jar::class) {
dependsOn("dokkaJavadoc")
archiveClassifier.set("javadoc")
from(javadoc)
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
archives(jar)
}
}
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
pom { /*...*/ }
}
}
}
}
from dokka.
This really helps. I think it should be added to the readme....
😅
from dokka.
Please check these thread in Kotlin discussion:
https://discuss.kotlinlang.org/t/generating-javadocs-kdocs-with-maven/839
from dokka.
A problem occurred evaluating project ':app'.
> Could not find property 'main' on SourceSet container.
It seems things are not so easy for android stuff. Ok, so that still leaves me in an 'investigation is pending' state :)
from dokka.
How would I go about generating a javadoc jar with the gradle plugin?
I have an android library written in kotlin and I'd like to have a javadoc.jar accompanying it.
I understand only a maven plugin supports this as of now? What are my options? :)
from dokka.
@jnizet Thank you!
Do you know by chance how one could also generate a sources.jar
using gradle task? I understand that this might not be dokka related, but so far I didn't find any example anywhere on how to do that (specifically for an android project)...
I need this because IntelliJ seems to take documentation only from sources.jar
: I even tried providing it a custom path to javadoc.jar
, but it doesn't do anything, in a project using my library its methods still look undocumented...
from dokka.
I'm talking here about a kotlin-based library which should have .kt
sources inside sources.jar
. kotlin's stdlib has it and it works, but I understand it uses maven for that...
from dokka.
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
from dokka.
For Gradle 7, I think a different approach is necessary. This is what I did:
// build.gradle.kts plugins { kotlin("jvm") version "1.5.31" // or whatever id("org.jetbrains.dokka") version "1.5.31" // or whatever `maven-publish` } java { withJavadocJar() } // This task is added by Gradle when we use java.withJavadocJar() val javadocJar = tasks.named<Jar>("javadocJar") { from(tasks.named("dokkaJavadoc")) } publishing { publications { create<MavenPublication>("my-library") { from(components["java"]) } } }This takes advantage of Gradle's built-in wiring with
java.withJavadocJar()
, which is important if you want the gradle module metadata (.module
file, cfpom.xml
) to include information on your documentation.
This helped me out a lot. Thanks!
from dokka.
Related Issues (20)
- Links to extensions with type parameters HOT 1
- [K2] Different DRI for varargs HOT 1
- Provide support to the Analysis API team in running and testing Dokka HOT 1
- AssertionError: Recursion detected in a lazy value under LockBasedStorageManager in multiplatform project HOT 2
- The location of KDoc in the code is not specified well
- Ability to reference symbols from within a block of code
- Avoid failing Dokka generation in jvm+androidJvm projects
- Provide a way to manually create SampleAnalysisEnvironment HOT 1
- Address review comments in the new Dokka Gradle DSL document
- Prepare for the release of Dokka 2.0.0
- [K2] Spike: research the behaviour of Kotlin/Java interop around getters/setters and inheritance HOT 1
- Set up playwright to run UI screenshot tests
- [K1] Resolved references to synthetic java properties
- Missed KDoc link if a comment starts with it
- [K2] Inconsistent documentable rendering order
- Make `DokkaBaseConfiguration.customAssets` lazy HOT 1
- The Dokka versioning dropdown is not visible HOT 2
- [email protected] HOT 5
- Any plan to support inline tag {@link} and block tag {@link} for kotlin comment? HOT 2
- Mentions of API excluded from the docs should not be links
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dokka.