diff options
author | aSemy <897017+aSemy@users.noreply.github.com> | 2023-02-21 17:50:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-21 17:50:02 +0100 |
commit | 0a09318eae5b21194507708af51a4469ec5d57aa (patch) | |
tree | 2567462cbcc1d936ecc8791c68438e6069eab03f /runners/gradle-plugin/src/main/kotlin | |
parent | f4a6a6a2d62174989e1106f279a6d578d90c22c1 (diff) | |
download | dokka-0a09318eae5b21194507708af51a4469ec5d57aa.tar.gz dokka-0a09318eae5b21194507708af51a4469ec5d57aa.tar.bz2 dokka-0a09318eae5b21194507708af51a4469ec5d57aa.zip |
Apply kotlin-dsl plugin (#2702)
Update code to use idiomatic Gradle API
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
3 files changed, 21 insertions, 18 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt index 412695ec..6e34676c 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt @@ -4,6 +4,7 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.internal.plugins.DslObject import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested +import org.gradle.kotlin.dsl.container import org.gradle.work.DisableCachingByDefault @DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") @@ -11,15 +12,14 @@ abstract class AbstractDokkaLeafTask : AbstractDokkaTask() { @get:Internal val dokkaSourceSets: NamedDomainObjectContainer<GradleDokkaSourceSetBuilder> = - project.container(GradleDokkaSourceSetBuilder::class.java, gradleDokkaSourceSetBuilderFactory()) - .also { container -> - DslObject(this).extensions.add("dokkaSourceSets", container) - project.kotlinOrNull?.sourceSets?.all { kotlinSourceSet -> - container.register(kotlinSourceSet.name) { dokkaSourceSet -> - dokkaSourceSet.configureWithKotlinSourceSet(kotlinSourceSet) - } + project.container(GradleDokkaSourceSetBuilder::class, gradleDokkaSourceSetBuilderFactory()).also { container -> + DslObject(this).extensions.add("dokkaSourceSets", container) + project.kotlinOrNull?.sourceSets?.all sourceSet@{ + container.register(name) { + configureWithKotlinSourceSet(this@sourceSet) } } + } /** * Only contains source sets that are marked with `isDocumented`. @@ -29,7 +29,7 @@ abstract class AbstractDokkaLeafTask : AbstractDokkaTask() { @get:Nested protected val unsuppressedSourceSets: List<GradleDokkaSourceSetBuilder> get() = dokkaSourceSets - .toList() - .also(::checkSourceSetDependencies) - .filterNot { it.suppress.getSafe() } + .toList() + .also(::checkSourceSetDependencies) + .filterNot { it.suppress.getSafe() } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/gradleConfigurations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/gradleConfigurations.kt index 7b924b75..86dd3716 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/gradleConfigurations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/gradleConfigurations.kt @@ -4,17 +4,18 @@ import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Dependency import org.gradle.api.attributes.Usage +import org.gradle.kotlin.dsl.named internal fun Project.maybeCreateDokkaDefaultPluginConfiguration(): Configuration { return configurations.maybeCreate("dokkaPlugin") { - attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) isCanBeConsumed = false } } internal fun Project.maybeCreateDokkaDefaultRuntimeConfiguration(): Configuration { return configurations.maybeCreate("dokkaRuntime") { - attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) isCanBeConsumed = false } } @@ -22,7 +23,7 @@ internal fun Project.maybeCreateDokkaDefaultRuntimeConfiguration(): Configuratio internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String, additionalDependencies: Collection<Dependency> = emptySet()): Configuration { return project.configurations.maybeCreate("${dokkaTaskName}Plugin") { extendsFrom(maybeCreateDokkaDefaultPluginConfiguration()) - attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) isCanBeConsumed = false dependencies.add(project.dokkaArtifacts.dokkaAnalysis) // compileOnly in base plugin dependencies.add(project.dokkaArtifacts.dokkaBase) @@ -33,10 +34,10 @@ internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String, internal fun Project.maybeCreateDokkaRuntimeConfiguration(dokkaTaskName: String): Configuration { return project.configurations.maybeCreate("${dokkaTaskName}Runtime") { extendsFrom(maybeCreateDokkaDefaultRuntimeConfiguration()) - attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")) + attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) isCanBeConsumed = false - defaultDependencies { dependencies -> - dependencies.add(project.dokkaArtifacts.dokkaCore) + defaultDependencies { + add(project.dokkaArtifacts.dokkaCore) } } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index 9fcb8e3b..37ec66c1 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -4,6 +4,8 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.UnknownDomainObjectException import org.gradle.util.Path +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.getByType import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget @@ -14,13 +16,13 @@ internal fun parsePath(path: String): Path = Path.path(path) internal val Project.kotlinOrNull: KotlinProjectExtension? get() = try { - project.extensions.findByType(KotlinProjectExtension::class.java) + project.extensions.findByType() } catch (e: NoClassDefFoundError) { null } internal val Project.kotlin: KotlinProjectExtension - get() = project.extensions.getByType(KotlinProjectExtension::class.java) + get() = project.extensions.getByType() internal fun Project.isAndroidProject() = try { project.extensions.getByName("android") |