Skip to content

Commit

Permalink
♻️ Refactor KotoolsSamplesJvmPlugin.apply(Project) method
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Sep 10, 2024
1 parent b4e9929 commit 2542855
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kotools.samples.gradle

import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.Directory
Expand Down Expand Up @@ -38,17 +39,20 @@ public class KotoolsSamplesJvmPlugin : Plugin<Project> {
val kotlin: KotlinJvmProjectExtension? = this.extensions.findByType()
checkNotNull(kotlin) { KotlinJvmPluginNotFound(this) }
val main: KotlinSourceSet = kotlin.sourceSets.getByName("main")
val sample: KotlinSourceSet = kotlin.sourceSets.create("sample") {
this.dependsOn(main)
val javaSamples: Directory = this@configureKotlinSourceSets.layout
.projectDirectory
.dir("src/sample/java")
this.kotlin.srcDir(javaSamples)
}
val sample: KotlinSourceSet = kotlin.sourceSets.sample(this)
sample.dependsOn(main)
kotlin.sourceSets.getByName("test")
.dependsOn(sample)
}

private fun NamedDomainObjectContainer<KotlinSourceSet>.sample(
project: Project
): KotlinSourceSet = this.create("sample") {
val javaSamples: Directory =
project.layout.projectDirectory.dir("src/sample/java")
this.kotlin.srcDir(javaSamples)
}

// ------------------------------ Conversions ------------------------------

/** Returns the string representation of this plugin. */
Expand Down

0 comments on commit 2542855

Please sign in to comment.