diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 79808cbba2..a5cfdd8b3a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ jimfs = "1.0" jmh = "1.34" jsr305 = "3.0.2" junit = "4.13.2" -kotlin = "1.6.10" +kotlin = "1.6.21" kotlinpoet = "1.12.0" ktlint = "0.42.1" moshi = "1.13.0" diff --git a/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt b/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt index 87f95a6b10..7e18c65907 100644 --- a/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt +++ b/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt @@ -4,6 +4,11 @@ package com.squareup.wire.gradle import com.squareup.wire.VERSION import com.squareup.wire.testing.withPlatformSlashes +import java.io.File +import java.io.IOException +import java.util.zip.ZipFile +import kotlin.text.RegexOption.DOT_MATCHES_ALL +import kotlin.text.RegexOption.MULTILINE import org.assertj.core.api.Assertions.assertThat import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner @@ -14,11 +19,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.io.File -import java.io.IOException -import java.util.zip.ZipFile -import kotlin.text.RegexOption.DOT_MATCHES_ALL -import kotlin.text.RegexOption.MULTILINE class WirePluginTest { @@ -34,14 +34,14 @@ class WirePluginTest { .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")) +// .withProjectDir(tmpFolder.newFolder("project-dir")) .withArguments( "-g", tmpFolder.newFolder("gradle-home").absolutePath, "generateProtos", "--stacktrace", "--info", - "--configuration-cache", +// "--configuration-cache", ) .withDebug(true) } @@ -1307,6 +1307,41 @@ class WirePluginTest { buildCacheDir.deleteRecursively() } + /** + * This project has a protoSource .jar + * caveman.jar + * + * It depends on another .jar, + * all-protos.jar + * + * We expect sources to be generated from cavemen.jar, but not all-protos.jar. + */ + @Test + fun sourcePathTransitiveDependenciesPulledAsProtoPathDependencies() { + val fixtureRoot = File("src/test/projects/sourcepath-dependencies-not-generated") + + val result = gradleRunner.runFixture(fixtureRoot) { build() } + + assertThat(result.task(":generateProtos")).isNotNull + assertThat(result.output) + .contains("Writing com.squareup.caveman.Caveman") + .doesNotContain("Writing com.squareup.dinosaurs.Dinosaur") + .doesNotContain("Writing com.squareup.geology.Period") + + assertThat( + File( + fixtureRoot, + "dinosaurs/build/generated/source/wire/com/squareup/caveman/Caveman.java" + ) + ).exists() + assertThat( + File( + fixtureRoot, + "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.java" + ) + ).doesNotExist() + } + private fun GradleRunner.runFixture( root: File, action: GradleRunner.() -> BuildResult diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar new file mode 100644 index 0000000000..60bbba784f Binary files /dev/null and b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar differ diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom new file mode 100644 index 0000000000..f83794c1af --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom @@ -0,0 +1,18 @@ + + + 4.0.0 + com.squareup.wire.dinosaur + caveman + 1.0 + POM was created from install:install-file + + + + com.squareup.wire.dinosaur + all-protos + 1.0 + + + + diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml new file mode 100644 index 0000000000..353887a45e --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml @@ -0,0 +1,12 @@ + + + com.squareup.wire.dinosaur + caveman + + 1.0 + + 1.0 + + 20220729023530 + + diff --git a/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle b/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle new file mode 100644 index 0000000000..bd46431742 --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'application' + id 'com.squareup.wire' +} + +// See installProtoJars task in wire-gradle-plugin/build.gradle.kts +repositories { + maven { + url "file://${projectDir.absolutePath}/../../../../../build/localMaven" + } +} + +wire { + sourcePath { + srcJar 'com.squareup.wire.dinosaur:caveman:+' + } + + // TODO(jwilson/enelson): make this dependency free by making the Gradle plugin smarter. + // protoPath { + // srcJar 'com.squareup.wire.dinosaur:all-protos:+' + // } + + java { + } +}