Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompileOnly for the KGP in wire-gradle-plugin #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Moving KGP to compileOnly may cause issues if the plugin relies on KGP classes at runtime


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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Circular dependency: wire-gradle-plugin depends on itself for tests

}

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Removing buildCache configuration may affect test behavior. Ensure this is intentional.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Removing the build cache configuration may affect caching behavior in tests. Ensure this is intentional and doesn't break any caching-related tests.

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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using a relative path for the build cache directory may cause issues if the project structure changes

}
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Absolute path for local Maven repository reduces build portability

}
}
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files(rootDir.resolve("../../../../../gradle/libs.versions.toml").absolutePath))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Absolute path for version catalog file may cause issues in different environments

}
}
}
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"
Comment on lines +3 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using the same version declaration style for both plugins for consistency

}

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

This file was deleted.

Loading