hfhbd
08/30/2022, 12:07 PM@get:OutputDirectory
abstract val outputFolder: DirectoryProperty
init {
outputFolder.convention(project.layout.buildDirectory.dir("generated/foo"))
project.plugins.withId("org.jetbrains.kotlin.jvm") {
val srcSet = project.extensions.findByType(SourceSetContainer::class.java)!!.getByName("main")
val kotlin = srcSet.extensions.getByName("kotlin") as SourceDirectorySet
kotlin.srcDir(outputFolder.dir("kotlin"))
}
}
tapchicoma
08/30/2022, 12:34 PMval kotlinExtension = project.extensions.getByName("kotlin") as KotlinProjectExtension
kotlinExtension.sourceSets.named("main") {
kotlin.srcDir(...)
}
hfhbd
08/30/2022, 1:28 PM@Test fun srcDir() {
val tmp = Files.createTempDirectory("testing").toFile().apply {
deleteOnExit()
}
val buildFile = File(tmp, "build.gradle.kts")
buildFile.writeText(
"""
plugins {
kotlin("jvm") version "1.7.20-Beta"
id("my.plugin")
}
repositories {
mavenCentral()
}
""".trimIndent()
)
val kotlinSrc = (tmp.toPath() / "src" / "main" / "kotlin" / "hello").toFile()
kotlinSrc.mkdirs()
File(kotlinSrc, "Test.kt").writeText(
"""
package hello
fun foo() {
main()
}
""".trimIndent()
)
val result = GradleRunner.create()
.withProjectDir(tmp)
.withArguments("myCodeGeneratorTask", "assemble", "--stacktrace")
.forwardOutput()
.withPluginClasspath()
.build()
assertEquals(TaskOutcome.SUCCESS, result.task(":myCodeGeneratorTask")?.outcome)
assertEquals(TaskOutcome.SUCCESS, result.task(":assemble")?.outcome)
}
tapchicoma
08/30/2022, 1:29 PMhfhbd
08/30/2022, 1:35 PMplugins {
`java-gradle-plugin`
id("com.github.johnrengelman.shadow")
}
gradlePlugin {
plugins {
create("myPlugin") {
id = "my.plugin"
implementationClass = "app.softwork.MyGradlePlugin"
}
}
}
dependencies {
compileOnly("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.20-Beta")
testImplementation(kotlin("test"))
testImplementation(gradleTestKit())
}
If I switch to implementation
, it works. But does it work, if my consumer uses an older Kotlin plugin?tapchicoma
08/30/2022, 3:31 PMhfhbd
08/30/2022, 3:34 PM