Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dokka documentation for Kotlin+Java projects #357

Merged
merged 6 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/dokka-for-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/

import io.spine.internal.dependency.Dokka
import io.spine.internal.gradle.dokka.onlyJavaSources

import java.time.LocalDate
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
Expand Down Expand Up @@ -56,6 +58,10 @@ dependencies {

tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
sourceRoots.setFrom(
onlyJavaSources()
)

skipEmptyPackages.set(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object Dokka {
object SpineExtensions {
private const val group = "io.spine.tools"

const val version = "2.0.0-SNAPSHOT.2"
const val version = "2.0.0-SNAPSHOT.3"
const val lib = "${group}:spine-dokka-extensions:${version}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.internal.gradle.dokka

import java.io.File
import java.time.LocalDate
import org.gradle.api.file.FileCollection
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.gradle.GradleDokkaSourceSetBuilder

/**
* Returns only Java source roots out of all present in the source set.
*
* It is a helper method for generating documentation by Dokka only for Java code. It is helpful
* when both Java and Kotlin source files are present in a source set. Dokka can properly generate
* documentation for either Kotlin or Java depending on the configuration, but not both.
*/
internal fun GradleDokkaSourceSetBuilder.onlyJavaSources(): FileCollection {
return sourceRoots.filter(File::isJavaSourceDirectory)
}

private fun File.isJavaSourceDirectory(): Boolean {
return isDirectory() && name == "java"
}