Skip to content

Commit 89604d3

Browse files
Merge KSP 1 and KSP 2 implementations into one module (#5768)
Consolidate all tasks into `KspModule` and introduce a config switch `kspModuleMode` (not a task) to have different task dependency depending on it's value. All tasks specific to only one version have a `ksp1` or `ksp2` in their name. All unit and integration tests should keep running successfully. I also envision to support KSP 2 In-Process mode, hence I implemented the mode switch as enum. Fix #5765 --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 905e508 commit 89604d3

File tree

10 files changed

+292
-327
lines changed

10 files changed

+292
-327
lines changed

example/kotlinlib/basic/7-dependency-injection/build.mill

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
package build
44
import mill.*, kotlinlib.*
5-
import kotlinlib.ksp.Ksp2Module
5+
import kotlinlib.ksp.KspModule
66

7-
object dagger extends Ksp2Module {
7+
object dagger extends KspModule {
88

99
def kotlinVersion = "2.2.0"
1010

@@ -24,7 +24,7 @@ object dagger extends Ksp2Module {
2424
mvn"com.google.dagger:dagger-compiler:2.57"
2525
)
2626

27-
object test extends Ksp2Tests, TestModule.Junit5 {
27+
object test extends KspTests, TestModule.Junit5 {
2828

2929
def kotlincOptions = super.kotlincOptions() ++ Seq("-no-reflect", "-verbose")
3030

@@ -46,14 +46,14 @@ object dagger extends Ksp2Module {
4646

4747
/** Usage
4848

49-
> ./mill show dagger.compile
49+
> ./mill dagger.compile
5050

51-
> ls out/dagger/generatedSourcesWithKSP.dest/generated/java/com/example/dagger/
51+
> ls out/dagger/generatedSourcesWithKsp2Cli.dest/generated/java/com/example/dagger/
5252
DaggerNumberApp.java
5353
NumberService_Factory.java
5454
RandomNumberGenerator_Factory.java
5555

56-
> ./mill show dagger.run
56+
> ./mill dagger.run
5757
Random number: ...
5858

5959
> ./mill show dagger.test
@@ -77,7 +77,7 @@ Random number: ...
7777
}
7878
...
7979

80-
> ls out/dagger/test/generatedSourcesWithKSP.dest/generated/java/com/example/dagger/
80+
> ls out/dagger/test/generatedSourcesWithKsp2Cli.dest/generated/java/com/example/dagger/
8181
ConstantNumberGenerator_Factory.java
8282
DaggerDemoComponent.java
8383
DaggerTestApp.java

example/kotlinlib/web/8-hello-micronaut/build.mill

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import coursier.{MavenRepository, Repository}
44

55
import mill.*
66
import kotlinlib.*
7-
import kotlinlib.ksp.Ksp2Module
7+
import kotlinlib.ksp.KspModule
88

99
object micronaut extends MicronautModule {
1010

@@ -29,7 +29,7 @@ object micronaut extends MicronautModule {
2929

3030
}
3131

32-
trait MicronautModule extends Ksp2Module { outer =>
32+
trait MicronautModule extends KspModule { outer =>
3333
def kspVersion: T[String] = "2.0.2"
3434
def kotlinVersion = "2.2.0"
3535
def kspJvmTarget: T[String] = "11"
@@ -50,17 +50,17 @@ trait MicronautModule extends Ksp2Module { outer =>
5050
}
5151

5252
override def resources: T[Seq[PathRef]] = Task {
53-
super.resources() ++ Seq(generatedSourcesWithKSP().resources)
53+
super.resources() ++ Seq(generatedSourcesWithKsp().resources)
5454
}
5555

5656
override def runClasspath: T[Seq[PathRef]] = Task {
57-
super.runClasspath() ++ Seq(generatedSourcesWithKSP().classes)
57+
super.runClasspath() ++ Seq(generatedSourcesWithKsp().classes)
5858
}
5959

60-
trait MicronautTests extends MicronautModule, Ksp2Tests {
60+
trait MicronautTests extends MicronautModule, KspTests {
6161

6262
override def resources: T[Seq[PathRef]] = Task {
63-
super[Ksp2Tests].resources() ++ Seq(generatedSourcesWithKSP().resources)
63+
super[KspTests].resources() ++ Seq(generatedSourcesWithKsp().resources)
6464
}
6565

6666
def kotlinSymbolProcessors = Seq(
@@ -69,8 +69,8 @@ trait MicronautModule extends Ksp2Module { outer =>
6969

7070
override def runClasspath: T[Seq[PathRef]] = Task {
7171
super.runClasspath() ++ Seq(
72-
generatedSourcesWithKSP().classes,
73-
outer.generatedSourcesWithKSP().classes
72+
generatedSourcesWithKsp().classes,
73+
outer.generatedSourcesWithKsp().classes
7474
)
7575
}
7676

example/thirdparty/androidtodo/build.mill

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package build
22

33
import mill.*, androidlib.*, kotlinlib.*
4-
import kotlinlib.ksp.Ksp2Module
4+
import kotlinlib.ksp.{KspModule, KspModuleMode}
55
import hilt.AndroidHiltSupport
66

77
object Versions {
@@ -19,12 +19,16 @@ object androidSdkModule0 extends AndroidSdkModule {
1919
}
2020

2121
// Mill configuration for the Android Todo App project.
22-
object app extends AndroidAppKotlinModule, AndroidR8AppModule, AndroidBuildConfig,
23-
Ksp2Module, AndroidHiltSupport {
22+
object app
23+
extends AndroidAppKotlinModule,
24+
AndroidR8AppModule,
25+
AndroidBuildConfig,
26+
AndroidHiltSupport {
2427

2528
def kotlinVersion = Versions.kotlinVersion
2629
def kspVersion = Versions.kspVersion
2730
def kspJvmTarget = "17"
31+
def kspModuleMode = KspModuleMode.Ksp2Cli
2832

2933
override def androidDebugSettings: T[AndroidBuildTypeSettings] = Task {
3034
AndroidBuildTypeSettings(
@@ -109,7 +113,7 @@ object app extends AndroidAppKotlinModule, AndroidR8AppModule, AndroidBuildConfi
109113
mvn"com.google.dagger:hilt-android-compiler:2.56"
110114
)
111115

112-
object test extends Ksp2Tests, AndroidAppKotlinTests, AndroidHiltSupport, TestModule.Junit4 {
116+
object test extends KspTests, AndroidAppKotlinTests, AndroidHiltSupport, TestModule.Junit4 {
113117

114118
def moduleDeps = super.moduleDeps ++ Seq(`shared-test`)
115119

@@ -145,8 +149,10 @@ object app extends AndroidAppKotlinModule, AndroidR8AppModule, AndroidBuildConfi
145149
)
146150
}
147151

148-
object androidTest extends AndroidAppKotlinInstrumentedTests, AndroidR8AppModule,
149-
Ksp2Module, AndroidHiltSupport {
152+
object androidTest
153+
extends AndroidAppKotlinInstrumentedTests,
154+
AndroidR8AppModule,
155+
AndroidHiltSupport {
150156

151157
def moduleDeps = super.moduleDeps ++ Seq(`shared-test`)
152158
def kspJvmTarget = "17"
@@ -211,7 +217,7 @@ object app extends AndroidAppKotlinModule, AndroidR8AppModule, AndroidBuildConfi
211217

212218
}
213219

214-
object `shared-test` extends AndroidKotlinModule, Ksp2Module, AndroidHiltSupport {
220+
object `shared-test` extends AndroidKotlinModule, AndroidHiltSupport {
215221

216222
def moduleDeps = Seq(app)
217223

libs/androidlib/src/mill/androidlib/hilt/AndroidHiltSupport.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package mill.androidlib.hilt
22

33
import mill.androidlib.AndroidKotlinModule
44
import mill.api.{ModuleRef, PathRef}
5-
import mill.kotlinlib.ksp.KspBaseModule
5+
import mill.kotlinlib.ksp.KspModule
66
import mill.javalib.Dep
77
import mill.javalib.api.CompilationResult
88
import mill.{T, Task}
@@ -18,16 +18,11 @@ import mill.{T, Task}
1818
*
1919
* Usage:
2020
* ```
21-
*
22-
* object app extends KspModule, AndroidHiltSupport { ... }
23-
*
24-
* // or
25-
*
26-
* object app extends Ksp2Module, AndroidHiltSupport { ... }
21+
* object app extends AndroidHiltSupport { ... }
2722
* ```
2823
*/
2924
@mill.api.experimental
30-
trait AndroidHiltSupport extends KspBaseModule, AndroidKotlinModule {
25+
trait AndroidHiltSupport extends KspModule, AndroidKotlinModule {
3126

3227
override def kspProcessorOptions: T[Map[String, String]] = Task {
3328
super.kspProcessorOptions() ++ Map(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mill.kotlinlib.ksp
2+
3+
import mill.api.PathRef
4+
import upickle.default.ReadWriter
5+
6+
@mill.api.experimental
7+
case class GeneratedKspSources(
8+
java: PathRef,
9+
kotlin: PathRef,
10+
resources: PathRef,
11+
classes: PathRef
12+
) derives ReadWriter {
13+
def sources: Seq[PathRef] = Seq(java, kotlin)
14+
}

libs/kotlinlib/src/mill/kotlinlib/ksp/Ksp2Module.scala

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)