Skip to content

Commit d1aaed0

Browse files
committed
CompileOnly for the KGP in wire-gradle-plugin
1 parent 907e375 commit d1aaed0

File tree

110 files changed

+426
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+426
-230
lines changed

Diff for: wire-gradle-plugin/build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ gradlePlugin {
3535
dependencies {
3636
compileOnly(gradleApi())
3737
compileOnly(libs.pluginz.android)
38+
compileOnly(libs.pluginz.kotlin)
3839

3940
implementation(projects.wireCompiler)
4041
implementation(projects.wireKotlinGenerator)
4142
implementation(libs.swiftpoet)
42-
implementation(libs.pluginz.kotlin)
4343

4444
testImplementation(libs.junit)
4545
testImplementation(libs.assertj)
46+
testImplementation(libs.pluginz.kotlin)
4647
testImplementation(projects.wireTestUtils)
4748
}
4849

@@ -55,6 +56,13 @@ tasks.withType<Test>().configureEach {
5556
jvmArgs("--add-opens", "java.base/java.util=ALL-UNNAMED")
5657
dependsOn(installProtoJars)
5758
dependsOn(":wire-runtime:installLocally")
59+
dependsOn(":wire-java-generator:publishAllPublicationsToLocalMavenRepository")
60+
dependsOn(":wire-kotlin-generator:publishAllPublicationsToLocalMavenRepository")
61+
dependsOn(":wire-swift-generator:publishAllPublicationsToLocalMavenRepository")
62+
dependsOn(":wire-schema:publishAllPublicationsToLocalMavenRepository")
63+
dependsOn(":wire-grpc-client:publishAllPublicationsToLocalMavenRepository")
64+
dependsOn(":wire-compiler:publishAllPublicationsToLocalMavenRepository")
65+
dependsOn(":wire-gradle-plugin:publishAllPublicationsToLocalMavenRepository")
5866
}
5967

6068
val test by tasks.getting(Test::class) {

Diff for: wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt

+41-19
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class WirePluginTest {
4747
@Before
4848
fun setUp() {
4949
gradleRunner = GradleRunner.create()
50-
.withPluginClasspath()
5150
// Ensure individual tests are isolated and not reusing each other's previous outputs
5251
// by setting project dir and gradle home directly.
5352
.withProjectDir(tmpFolder.newFolder("project-dir"))
@@ -58,6 +57,7 @@ class WirePluginTest {
5857
"--stacktrace",
5958
"--info",
6059
"--configuration-cache",
60+
"-PwireVersion=$VERSION",
6161
)
6262
.withDebug(true)
6363
}
@@ -456,7 +456,7 @@ class WirePluginTest {
456456
val fixtureRoot = File("src/test/projects/project-dependencies-typesafe-accessor")
457457

458458
val result = gradleRunner.runFixture(fixtureRoot) {
459-
withArguments("generateMainProtos", "--stacktrace", "--info").build()
459+
withArguments("generateMainProtos", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
460460
}
461461

462462
assertThat(result.task(":dinosaurs:generateMainProtos")?.outcome)
@@ -646,7 +646,7 @@ class WirePluginTest {
646646
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
647647

648648
val result = gradleRunner.runFixture(fixtureRoot) {
649-
withArguments("run", "--stacktrace", "--info").build()
649+
withArguments("run", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
650650
}
651651

652652
assertThat(result.task(":generateMainProtos")).isNotNull()
@@ -660,7 +660,7 @@ class WirePluginTest {
660660
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
661661

662662
val result = gradleRunner.runFixture(fixtureRoot) {
663-
withArguments("run", "--stacktrace", "--info").build()
663+
withArguments("run", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
664664
}
665665

666666
assertThat(result.task(":generateMainProtos")).isNotNull()
@@ -674,7 +674,7 @@ class WirePluginTest {
674674
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
675675

676676
val result = gradleRunner.runFixture(fixtureRoot) {
677-
withArguments("run", "--stacktrace", "--info").build()
677+
withArguments("run", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
678678
}
679679

680680
assertThat(result.task(":generateMainProtos")).isNotNull()
@@ -688,7 +688,7 @@ class WirePluginTest {
688688
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
689689

690690
val result = gradleRunner.runFixture(fixtureRoot) {
691-
withArguments("run", "--stacktrace", "--info").build()
691+
withArguments("run", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
692692
}
693693

694694
assertThat(result.task(":generateMainProtos")).isNotNull()
@@ -701,7 +701,7 @@ class WirePluginTest {
701701
val fixtureRoot = File("src/test/projects/proto-library")
702702

703703
gradleRunner.runFixture(fixtureRoot) {
704-
withArguments("jar", "--stacktrace", "--info").build()
704+
withArguments("jar", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
705705
}
706706

707707
ZipFile(File(fixtureRoot, "build/libs/proto-library.jar")).use {
@@ -729,7 +729,7 @@ class WirePluginTest {
729729
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
730730

731731
val result = gradleRunner.runFixture(fixtureRoot) {
732-
withArguments("run", "--stacktrace", "--info").build()
732+
withArguments("run", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
733733
}
734734

735735
assertThat(result.task(":generateMainProtos")).isNotNull()
@@ -973,6 +973,7 @@ class WirePluginTest {
973973
"-Dkjs=$kmpJsEnabled",
974974
"-Dknative=$kmpNativeEnabled",
975975
"--debug",
976+
"-PwireVersion=$VERSION",
976977
).build()
977978
}
978979

@@ -1219,7 +1220,7 @@ class WirePluginTest {
12191220
val geologyOutputRoot = File(fixtureRoot, "geology/build/generated/source/wire")
12201221

12211222
val result = gradleRunner.runFixture(fixtureRoot) {
1222-
withArguments("generateMainProtos", "--stacktrace", "--info").build()
1223+
withArguments("generateMainProtos", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
12231224
}
12241225

12251226
assertThat(result.task(":dinosaurs:generateMainProtos")?.outcome)
@@ -1247,7 +1248,7 @@ class WirePluginTest {
12471248

12481249
val fixtureRoot = File("src/test/projects/cache-relocation-1")
12491250
val result = gradleRunner.runFixture(fixtureRoot) {
1250-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info").build()
1251+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
12511252
}
12521253

12531254
assertThat(result.task(":generateProtos")).isNotNull()
@@ -1261,7 +1262,7 @@ class WirePluginTest {
12611262

12621263
val relocatedRoot = File("src/test/projects/cache-relocation-2")
12631264
val relocatedResult = gradleRunner.runFixture(relocatedRoot) {
1264-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info").build()
1265+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
12651266
}
12661267

12671268
assertThat(relocatedResult.task(":generateProtos")).isNotNull()
@@ -1284,7 +1285,7 @@ class WirePluginTest {
12841285

12851286
val fixtureRoot = File("src/test/projects/cache-include-paths-1")
12861287
val result = gradleRunner.runFixture(fixtureRoot) {
1287-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug").build()
1288+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug", "-PwireVersion=$VERSION").build()
12881289
}
12891290

12901291
assertThat(result.task(":generateProtos")).isNotNull()
@@ -1296,7 +1297,7 @@ class WirePluginTest {
12961297
assertThat(buildCacheDir.exists()).isTrue()
12971298

12981299
val cachedResult = gradleRunner.runFixture(fixtureRoot) {
1299-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug").build()
1300+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug", "-PwireVersion=$VERSION").build()
13001301
}
13011302

13021303
assertThat(cachedResult.task(":generateProtos")).isNotNull()
@@ -1320,7 +1321,7 @@ class WirePluginTest {
13201321

13211322
val fixtureRoot = File("src/test/projects/cache-include-paths-1")
13221323
val result = gradleRunner.runFixture(fixtureRoot) {
1323-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info").build()
1324+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
13241325
}
13251326

13261327
assertThat(result.task(":generateProtos")).isNotNull()
@@ -1336,7 +1337,7 @@ class WirePluginTest {
13361337
// expect the new task to run again, without using the cache.
13371338
val modifiedFixtureRoot = File("src/test/projects/cache-include-paths-2")
13381339
val modifiedResult = gradleRunner.runFixture(modifiedFixtureRoot) {
1339-
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug").build()
1340+
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug", "-PwireVersion=$VERSION").build()
13401341
}
13411342

13421343
assertThat(modifiedResult.task(":generateProtos")).isNotNull()
@@ -1355,7 +1356,7 @@ class WirePluginTest {
13551356
val fixtureRoot = File("src/test/projects/configuration-cache-failure")
13561357

13571358
val result = gradleRunner.runFixture(fixtureRoot) {
1358-
withArguments("clean", "generateMainProtos", "--stacktrace", "--info").build()
1359+
withArguments("clean", "generateMainProtos", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
13591360
}
13601361
assertThat(result.task(":generateMainProtos")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
13611362
}
@@ -1365,7 +1366,7 @@ class WirePluginTest {
13651366
val fixtureRoot = File("src/test/projects/kotlinsourcesjar")
13661367

13671368
gradleRunner.runFixture(fixtureRoot) {
1368-
withArguments("clean", "kotlinSourcesJar", "--stacktrace", "--info").build()
1369+
withArguments("clean", "kotlinSourcesJar", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
13691370
}
13701371

13711372
ZipFile(File(fixtureRoot, "build/libs/kotlinsourcesjar-sources.jar")).use {
@@ -1379,7 +1380,7 @@ class WirePluginTest {
13791380
val outputRoot = File(fixtureRoot, "build/generated/source/wire")
13801381

13811382
val result = gradleRunner.runFixture(fixtureRoot) {
1382-
withArguments("clean", "generateMainProtos", "--stacktrace", "--info").build()
1383+
withArguments("clean", "generateMainProtos", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
13831384
}
13841385
assertThat(result.task(":generateMainProtos")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
13851386
assertThat(File(outputRoot, "Dinosaur.kt")).exists()
@@ -1391,12 +1392,33 @@ class WirePluginTest {
13911392
action: GradleRunner.() -> BuildResult,
13921393
): BuildResult {
13931394
var generatedSettings = false
1394-
val settings = File(root, "settings.gradle")
1395+
val settings = File(root, "settings.gradle.kts")
13951396
var generatedGradleProperties = false
13961397
val gradleProperties = File(root, "gradle.properties")
13971398
return try {
13981399
if (!settings.exists()) {
13991400
settings.createNewFile()
1401+
settings.writeText(
1402+
"""
1403+
|pluginManagement {
1404+
| listOf(repositories, dependencyResolutionManagement.repositories).forEach {
1405+
| it.apply {
1406+
| mavenCentral()
1407+
| maven {
1408+
| url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
1409+
| }
1410+
| }
1411+
| }
1412+
|}
1413+
|
1414+
|dependencyResolutionManagement {
1415+
| versionCatalogs {
1416+
| create("libs").from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
1417+
| }
1418+
|}
1419+
|
1420+
""".trimMargin(),
1421+
)
14001422
generatedSettings = true
14011423
}
14021424

Diff for: wire-gradle-plugin/src/test/projects/cache-include-paths-1/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm'
3-
id 'com.squareup.wire'
2+
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
3+
id 'com.squareup.wire' version "$wireVersion"
44
}
55

66
// This file should be kept in sync with `cache-include-paths-2/build.gradle` with the exception of

Diff for: wire-gradle-plugin/src/test/projects/cache-include-paths-1/settings.gradle

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
buildCache {
2+
local {
3+
directory = File(rootDir, "../.cache-include-paths-build-cache")
4+
}
5+
}
6+
7+
pluginManagement {
8+
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
9+
it.apply {
10+
mavenCentral()
11+
maven {
12+
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
13+
}
14+
}
15+
}
16+
}
17+
18+
dependencyResolutionManagement {
19+
versionCatalogs {
20+
create("libs") {
21+
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
22+
}
23+
}
24+
}

Diff for: wire-gradle-plugin/src/test/projects/cache-include-paths-2/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm'
3-
id 'com.squareup.wire'
2+
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
3+
id 'com.squareup.wire' version "$wireVersion"
44
}
55

66
// This file should be kept in sync with `cache-include-paths-1/build.gradle` with the exception of

Diff for: wire-gradle-plugin/src/test/projects/cache-include-paths-2/settings.gradle

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
buildCache {
2+
local {
3+
directory = File(rootDir, "../.cache-include-paths-build-cache")
4+
}
5+
}
6+
7+
pluginManagement {
8+
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
9+
it.apply {
10+
mavenCentral()
11+
maven {
12+
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
13+
}
14+
}
15+
}
16+
}
17+
18+
dependencyResolutionManagement {
19+
versionCatalogs {
20+
create("libs") {
21+
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
22+
}
23+
}
24+
}

Diff for: wire-gradle-plugin/src/test/projects/cache-relocation-1/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'application'
3-
id 'org.jetbrains.kotlin.jvm'
4-
id 'com.squareup.wire'
3+
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
4+
id 'com.squareup.wire' version "$wireVersion"
55
}
66

77
// The code in this test project should be identical to

Diff for: wire-gradle-plugin/src/test/projects/cache-relocation-1/settings.gradle

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
buildCache {
2+
local {
3+
directory = File(rootDir, "../.relocation-build-cache")
4+
}
5+
}
6+
7+
pluginManagement {
8+
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
9+
it.apply {
10+
mavenCentral()
11+
maven {
12+
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
13+
}
14+
}
15+
}
16+
}
17+
18+
dependencyResolutionManagement {
19+
versionCatalogs {
20+
create("libs") {
21+
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
22+
}
23+
}
24+
}

Diff for: wire-gradle-plugin/src/test/projects/cache-relocation-2/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'application'
3-
id 'org.jetbrains.kotlin.jvm'
4-
id 'com.squareup.wire'
3+
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
4+
id 'com.squareup.wire' version "$wireVersion"
55
}
66

77
// The code in this test project should be identical to

Diff for: wire-gradle-plugin/src/test/projects/cache-relocation-2/settings.gradle

-5
This file was deleted.

0 commit comments

Comments
 (0)