Skip to content

Commit

Permalink
initial copy and tidy up and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
aSemy committed Feb 7, 2023
0 parents commit 8aa0464
Show file tree
Hide file tree
Showing 55 changed files with 4,916 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf


# Exclude external libs from GitHub language stats https://github.com/github/linguist/blob/v7.24.1/docs/overrides.md
externals/*/** linguist-vendored
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

.idea
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Dokkatoo

Generates documentation from Kotlin code.

Based on Kotlin Dokka.

* Compatible with Gradle Build Cache
* Compatible with Gradle Configuration Cache
* Safe cross-project sharing and aggregation

## Usage

```kts
// build.gradle.kts

plugins {
id("dev.adamko.dokkatoo") version "0.0.1-SNAPSHOT"
}

dokkatoo {
// ...
}
```

```shell
# generate all sites
./gradlew dokkatooGenerate

# only generate a single format
./gradlew dokkatooGenerateHtml
./gradlew dokkatooGenerateGfm
./gradlew dokkatooGenerateJekyll
./gradlew dokkatooGenerateJavadoc
```

### Combining subprojects

Any subproject can aggregate multiple subprojects into one Dokka Publication.

```kts
// ./build.gradle.kts

plugins {
kotlin("jvm") version "1.8.0" apply false // required by Gradle
id("dev.adamko.dokkatoo") version "0.0.1-SNAPSHOT"
}

dependencies {
// aggregate both subproject-hello and subproject-world
// the subprojects must also have Dokkatoo applied
dokkatoo(projects(":subproject-hello"))
dokkatoo(projects(":subproject-world"))
}
```
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
buildsrc.conventions.base
}

group = "dev.adamko"
version = "0.0.1-SNAPSHOT"
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
`kotlin-dsl`
}
19 changes: 19 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rootProject.name = "buildSrc"

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature
dependencyResolutionManagement {

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

repositories {
mavenCentral()
gradlePluginPortal()
}
}
62 changes: 62 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/conventions/base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package buildsrc.conventions

import buildsrc.conventions.utils.asConsumer
import buildsrc.conventions.utils.asProvider
import buildsrc.conventions.utils.dropDirectories
import java.time.Duration
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
base
}

// common config for all projects

if (project != rootProject) {
project.version = rootProject.version
project.group = rootProject.group
}

tasks.withType<AbstractArchiveTask>().configureEach {
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

tasks.withType<AbstractTestTask>().configureEach {
timeout.set(Duration.ofMinutes(10))

testLogging {
showCauses = true
showExceptions = true
showStackTraces = true
showStandardStreams = true
events(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STARTED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT,
)
}
}

tasks.withType<AbstractCopyTask>().configureEach {
includeEmptyDirs = false
}


val kotlinDokkaSource by configurations.registering {
asConsumer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named("rocksdb-src"))
}
}

val kotlinDokkaSourceElements by configurations.registering {
asProvider()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named("rocksdb-src"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package buildsrc.conventions.buildsrc.conventions

import gradle.kotlin.dsl.accessors._1aa7e5c26223e2b5ce19d03a79e08c0e.java
import gradle.kotlin.dsl.accessors._1aa7e5c26223e2b5ce19d03a79e08c0e.pluginDescriptors
import gradle.kotlin.dsl.accessors._1aa7e5c26223e2b5ce19d03a79e08c0e.sourceSets
import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.`java-gradle-plugin`
import org.gradle.kotlin.dsl.named

plugins {
`java-gradle-plugin`
}

fun registerGradleVariant(name: String, gradleVersion: String) {
val variantSources = sourceSets.create(name)

java {
registerFeature(variantSources.name) {
usingSourceSet(variantSources)
// capability("${project.group}", "${project.name}", "${project.version}")
capability("org.jetbrains.dokka", "${project.name}", "2.0.0")

withJavadocJar()
withSourcesJar()
}
}

configurations
.matching { it.isCanBeConsumed && it.name.startsWith(variantSources.name) }
.configureEach {
attributes {
attribute(GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(gradleVersion))
}
}

tasks.named<Copy>(variantSources.processResourcesTaskName) {
val copyPluginDescriptors = rootSpec.addChild()
copyPluginDescriptors.into("META-INF/gradle-plugins")
// copyPluginDescriptors.into(tasks.pluginDescriptors.flatMap { it.outputDirectory })
copyPluginDescriptors.from(tasks.pluginDescriptors)
}

dependencies {
add(variantSources.compileOnlyConfigurationName, gradleApi())
}
}

//registerGradleVariant("gradle5", "5.0")
//registerGradleVariant("gradle6", "6.0")
registerGradleVariant("gradle7", "7.0")
registerGradleVariant("gradle8", "8.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package buildsrc.distributions
50 changes: 50 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/utils/gradle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package buildsrc.conventions.utils

import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.RelativePath

/**
* Mark this [Configuration] as one that will be consumed by other subprojects.
*
* ```
* isCanBeResolved = false
* isCanBeConsumed = true
* ```
*/
fun Configuration.asProvider() {
isCanBeResolved = false
isCanBeConsumed = true
}

/**
* Mark this [Configuration] as one that will consume artifacts from other subprojects (also known as 'resolving')
*
* ```
* isCanBeResolved = true
* isCanBeConsumed = false
* ```
* */
fun Configuration.asConsumer() {
isCanBeResolved = true
isCanBeConsumed = false
}


/** Drop the first [count] directories from the path */
fun RelativePath.dropDirectories(count: Int): RelativePath =
RelativePath(true, *segments.drop(count).toTypedArray())


/** Drop the first directory from the path */
fun RelativePath.dropDirectory(): RelativePath =
dropDirectories(1)


/** Drop the first directory from the path */
fun RelativePath.dropDirectoriesWhile(
segmentPrediate: (segment: String) -> Boolean
): RelativePath =
RelativePath(
true,
*segments.dropWhile(segmentPrediate).toTypedArray(),
)
1 change: 1 addition & 0 deletions externals/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin-dokka/
45 changes: 45 additions & 0 deletions externals/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import buildsrc.conventions.utils.*

plugins {
buildsrc.conventions.base
}


//
//val kotlinDokkaSource by configurations.creating<Configuration> {
// asConsumer()
// attributes {
// attribute(Usage.USAGE_ATTRIBUTE, objects.named("rocksdb-src"))
// }
//}

dependencies {
kotlinDokkaSource("kotlin:dokka:1.7.20@zip")
}

val kotlinDokkaPrepareSource by tasks.registering(Sync::class) {
group = "externals"
description = "Download & unpack Kotlin Dokka source code"
from(
@Suppress("UnstableApiUsage")
configurations.kotlinDokkaSource.flatMap { src ->
src.incoming
.artifactView { lenient(true) }
.artifacts
.resolvedArtifacts
.map { artifacts -> artifacts.map { zipTree(it.file) } }
}
) {
// drop the first dir (rocksdb-$version)
eachFile {
relativePath = relativePath.dropDirectories(1)
}
}
into(layout.projectDirectory.dir("kotlin-dokka"))
}

configurations.kotlinDokkaSourceElements.configure {
outgoing {
artifact(kotlinDokkaPrepareSource.map { it.destinationDir })
}
}
11 changes: 11 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx2g -XX:MaxMetaspaceSize=1g

org.gradle.caching=true
# https://github.com/gradle/gradle/issues/20416
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true

org.gradle.unsafe.configuration-cache=true
org.gradle.unsafe.configuration-cache-problems=warn

org.gradle.parallel=true
org.gradle.welcome=never
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 8aa0464

Please sign in to comment.