Skip to content

Commit

Permalink
CompileOnly for the KGP in wire-gradle-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Sep 12, 2024
1 parent 907e375 commit d1aaed0
Show file tree
Hide file tree
Showing 110 changed files with 426 additions and 230 deletions.
10 changes: 9 additions & 1 deletion wire-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ gradlePlugin {
dependencies {
compileOnly(gradleApi())
compileOnly(libs.pluginz.android)
compileOnly(libs.pluginz.kotlin)

implementation(projects.wireCompiler)
implementation(projects.wireKotlinGenerator)
implementation(libs.swiftpoet)
implementation(libs.pluginz.kotlin)

testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.pluginz.kotlin)
testImplementation(projects.wireTestUtils)
}

Expand All @@ -55,6 +56,13 @@ tasks.withType<Test>().configureEach {
jvmArgs("--add-opens", "java.base/java.util=ALL-UNNAMED")
dependsOn(installProtoJars)
dependsOn(":wire-runtime:installLocally")
dependsOn(":wire-java-generator:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-kotlin-generator:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-swift-generator:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-schema:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-grpc-client:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-compiler:publishAllPublicationsToLocalMavenRepository")
dependsOn(":wire-gradle-plugin:publishAllPublicationsToLocalMavenRepository")
}

val test by tasks.getting(Test::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class WirePluginTest {
@Before
fun setUp() {
gradleRunner = GradleRunner.create()
.withPluginClasspath()
// Ensure individual tests are isolated and not reusing each other's previous outputs
// by setting project dir and gradle home directly.
.withProjectDir(tmpFolder.newFolder("project-dir"))
Expand All @@ -58,6 +57,7 @@ class WirePluginTest {
"--stacktrace",
"--info",
"--configuration-cache",
"-PwireVersion=$VERSION",
)
.withDebug(true)
}
Expand Down Expand Up @@ -456,7 +456,7 @@ class WirePluginTest {
val fixtureRoot = File("src/test/projects/project-dependencies-typesafe-accessor")

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

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

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

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

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

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

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

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

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

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

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

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

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

assertThat(result.task(":generateMainProtos")).isNotNull()
Expand Down Expand Up @@ -973,6 +973,7 @@ class WirePluginTest {
"-Dkjs=$kmpJsEnabled",
"-Dknative=$kmpNativeEnabled",
"--debug",
"-PwireVersion=$VERSION",
).build()
}

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

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

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

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

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

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

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

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

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

val cachedResult = gradleRunner.runFixture(fixtureRoot) {
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug").build()
withArguments("generateProtos", "--build-cache", "--stacktrace", "--debug", "-PwireVersion=$VERSION").build()
}

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

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

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

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

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

gradleRunner.runFixture(fixtureRoot) {
withArguments("clean", "kotlinSourcesJar", "--stacktrace", "--info").build()
withArguments("clean", "kotlinSourcesJar", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
}

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

val result = gradleRunner.runFixture(fixtureRoot) {
withArguments("clean", "generateMainProtos", "--stacktrace", "--info").build()
withArguments("clean", "generateMainProtos", "--stacktrace", "--info", "-PwireVersion=$VERSION").build()
}
assertThat(result.task(":generateMainProtos")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(File(outputRoot, "Dinosaur.kt")).exists()
Expand All @@ -1391,12 +1392,33 @@ class WirePluginTest {
action: GradleRunner.() -> BuildResult,
): BuildResult {
var generatedSettings = false
val settings = File(root, "settings.gradle")
val settings = File(root, "settings.gradle.kts")
var generatedGradleProperties = false
val gradleProperties = File(root, "gradle.properties")
return try {
if (!settings.exists()) {
settings.createNewFile()
settings.writeText(
"""
|pluginManagement {
| listOf(repositories, dependencyResolutionManagement.repositories).forEach {
| it.apply {
| mavenCentral()
| maven {
| url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
| }
| }
| }
|}
|
|dependencyResolutionManagement {
| versionCatalogs {
| create("libs").from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
| }
|}
|
""".trimMargin(),
)
generatedSettings = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'com.squareup.wire'
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
id 'com.squareup.wire' version "$wireVersion"
}

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
buildCache {
local {
directory = File(rootDir, "../.cache-include-paths-build-cache")
}
}

pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
mavenCentral()
maven {
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
}
}
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'com.squareup.wire'
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
id 'com.squareup.wire' version "$wireVersion"
}

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
buildCache {
local {
directory = File(rootDir, "../.cache-include-paths-build-cache")
}
}

pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
mavenCentral()
maven {
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
}
}
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'application'
id 'org.jetbrains.kotlin.jvm'
id 'com.squareup.wire'
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
id 'com.squareup.wire' version "$wireVersion"
}

// The code in this test project should be identical to
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
buildCache {
local {
directory = File(rootDir, "../.relocation-build-cache")
}
}

pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
mavenCentral()
maven {
url = uri(rootDir.resolve("../../../../../build/localMaven").absolutePath)
}
}
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'application'
id 'org.jetbrains.kotlin.jvm'
id 'com.squareup.wire'
id 'org.jetbrains.kotlin.jvm' version libs.versions.kotlin
id 'com.squareup.wire' version "$wireVersion"
}

// The code in this test project should be identical to
Expand Down

This file was deleted.

Loading

0 comments on commit d1aaed0

Please sign in to comment.