Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package schwarz.it.lightsaber.gradle
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import schwarz.it.lightsaber.gradle.truth.assertThat
import java.io.File
import java.nio.file.Files
Expand Down Expand Up @@ -45,10 +47,11 @@ class LightsaberPluginIntegrationTest {
assertThat(buildResult).doesNotContain("warning:")
}

@Test
fun ksp() {
@ParameterizedTest
@ValueSource(strings = ["ksp1", "ksp2"])
fun ksp(resourcePath: String) {
val buildResult = GradleRunner.create()
.withProjectDirFromResources("ksp")
.withProjectDirFromResources(resourcePath)
.withPluginClasspath()
.withArguments("lightsaberCheck")
.buildAndFail()
Expand Down Expand Up @@ -108,10 +111,11 @@ class LightsaberPluginIntegrationTest {
assertThat(buildResult).doesNotContain("warning:")
}

@Test
fun ksp_cache() {
@ParameterizedTest
@ValueSource(strings = ["ksp1", "ksp2"])
fun ksp_cache(resourcePath: String) {
val runner = GradleRunner.create()
.withProjectDirFromResources("ksp")
.withProjectDirFromResources(resourcePath)
.withPluginClasspath()
.withArguments("lightsaberCheck", "--build-cache")

Expand Down Expand Up @@ -166,10 +170,11 @@ class LightsaberPluginIntegrationTest {
assertThat(buildResult).doesNotContain("warning:")
}

@Test
fun androidKsp() {
@ParameterizedTest
@ValueSource(strings = ["androidKsp1", "androidKsp2"])
fun androidKsp(resourcePath: String) {
val buildResult = GradleRunner.create()
.withProjectDirFromResources("androidKsp")
.withProjectDirFromResources(resourcePath)
.withPluginClasspath()
.withArguments("lightsaberCheck")
.buildAndFail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.File
class LightsaberPluginOtherTasksTest {

@ParameterizedTest
@ValueSource(strings = ["annotationProcessor", "kapt", "ksp", "androidAnnotationProcessor", "androidKapt", "androidKsp"])
@ValueSource(strings = ["annotationProcessor", "kapt", "ksp1", "ksp2", "androidAnnotationProcessor", "androidKapt", "androidKsp1", "androidKsp2"])
fun `Execute test task correctly`(resourcePath: String) {
val dir: File
GradleRunner.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id("com.android.application") version "8.10.1"
id("io.github.schwarzit.lightsaber")
kotlin("android") version "2.0.21"
id("com.google.devtools.ksp") version "2.0.21-1.0.28"
}

@OptIn(com.google.devtools.ksp.KspExperimental::class)
ksp {
useKsp2.set(false)
}

android {
compileSdk = 33
namespace = "test.namespace"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

dependencies {
implementation("com.google.dagger:dagger:2.48.1")
ksp("com.google.dagger:dagger-compiler:2.48.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ plugins {
id("com.google.devtools.ksp") version "2.0.21-1.0.28"
}

@OptIn(com.google.devtools.ksp.KspExperimental::class)
ksp {
useKsp2.set(true)
}

android {
compileSdk = 33
namespace = "test.namespace"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rootProject.name = "lightsaber-android-kapt-test"

pluginManagement {
repositories {
mavenCentral()
google()
}
}

dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
google()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example

import dagger.Component
import dagger.Module
import dagger.Provides

@Component(modules = [MyModule::class])
interface MyComponent {
fun myInt(): Int
}

@Module
abstract class MyModule {

companion object {
@Provides
fun myInt(): Int {
return 42
}

@Provides
fun myLong(): Long {
return 42L
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
kotlin("jvm") version "2.0.21"
id("com.google.devtools.ksp") version "2.0.21-1.0.28"
id("io.github.schwarzit.lightsaber")
}

@OptIn(com.google.devtools.ksp.KspExperimental::class)
ksp {
useKsp2.set(false)
}

dependencies {
implementation("com.google.dagger:dagger:2.48.1")
ksp("com.google.dagger:dagger-compiler:2.48.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ plugins {
id("io.github.schwarzit.lightsaber")
}

@OptIn(com.google.devtools.ksp.KspExperimental::class)
ksp {
useKsp2.set(true)
}

dependencies {
implementation("com.google.dagger:dagger:2.48.1")
ksp("com.google.dagger:dagger-compiler:2.48.1")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "lightsaber-ksp-test"

dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
google()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example

import dagger.Component
import dagger.Module
import dagger.Provides
import javax.inject.Inject

@Component(modules = [MyModule::class])
interface MyComponent {
fun myInt(): Int
fun foo(): Foo
}

@Module
abstract class MyModule {

companion object {
@Provides
fun myInt(): Int {
return 42
}

@Provides
fun myLong(): Long {
return 42L
}

@Provides
fun provideFoo(): Foo = Foo()
}
}

class Foo @Inject constructor()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package schwarz.it.lightsaber.gradle.processors

import com.google.devtools.ksp.gradle.KspAATask
import com.google.devtools.ksp.gradle.KspExtension
import com.google.devtools.ksp.gradle.KspTaskJvm
import org.gradle.api.Project
Expand All @@ -19,24 +20,43 @@ internal fun Project.registerKspTask(
val lightsaberCheck = registerTask(extension, variantName.orEmpty())
lightsaberCheck.configure { task ->
val lightsaberOutputDir = lightsaberOutputDir("ksp")
val taskProvider = provider {
tasks.withType(KspTaskJvm::class.java)
.matching { it.name.startsWith("ksp${variantName.orEmpty()}") }
.apply {
configureEach { kspTask ->
val sourceSet = kspTask.name
.removePrefix("kapt")
.removeSuffix("Kotlin")
.ifEmpty { "main" }
.replaceFirstChar { it.lowercaseChar() }
val output = lightsaberOutputDir.map { it.dir(sourceSet) }
kspTask.commandLineArgumentProviders.add(LightsaberArgumentProvider(output, ksp = true))
task.dependsOn(
project.extensions.getByType(KspExtension::class.java).useKsp2.map { useKsp2 ->
if (useKsp2) {
tasks.withType(KspAATask::class.java)
.matching { it.name.startsWith("ksp${variantName.orEmpty()}") }
.apply {
configureEach { kspTask ->
val sourceSet = kspTask.name
.removePrefix("ksp")
.removeSuffix("Kotlin")
.ifEmpty { "main" }
.replaceFirstChar { it.lowercaseChar() }
val output = lightsaberOutputDir.map { it.dir(sourceSet) }
kspTask.commandLineArgumentProviders.add(LightsaberArgumentProvider(output, ksp = true))

kspTask.outputs.dir(output)
}
kspTask.outputs.dir(output)
}
}
} else {
tasks.withType(KspTaskJvm::class.java)
.matching { it.name.startsWith("ksp${variantName.orEmpty()}") }
.apply {
configureEach { kspTask ->
val sourceSet = kspTask.name
.removePrefix("ksp")
.removeSuffix("Kotlin")
.ifEmpty { "main" }
.replaceFirstChar { it.lowercaseChar() }
val output = lightsaberOutputDir.map { it.dir(sourceSet) }
kspTask.commandLineArgumentProviders.add(LightsaberArgumentProvider(output, ksp = true))

kspTask.outputs.dir(output)
}
}
}
}
task.dependsOn(taskProvider)
},
)

task.source += fileTree(lightsaberOutputDir)
}
Expand Down
Loading