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

Pass dependencies symbolically to WireTask for better Gradle caching #2842

Open
swankjesse opened this issue Feb 27, 2024 · 1 comment
Open

Comments

@swankjesse
Copy link
Member

Right now we pass dependencies to WireTask as the absolute paths to the resolved artifact, like so:

/Users/jwilson/.m2/repository/com/squareup/wire/dinosaur/all-protos/1.0/all-protos-1.0.jar

This won’t work for shared Gradle caches. We should instead use a symbolic identifier like com.squareup.wire.dinosaur:all-protos:1.0 that is independent of the current environment’s artifact directory.

@martinbonnin
Copy link
Collaborator

At the end of the day, I think the task inputs should be ConfigurableFileCollection everywhere. ConfigurableFileCollections can contain:

  • a local zipTree
  • a fileTree folder + include rules
  • or a configuration with project() dependencies.

Which I think covers all the use cases? Then the task could be trimmed down to just:

abstract class WireTask @Inject constructor(
  objects: ObjectFactory,
  private val fileOperations: FileOperations,
) : DefaultTask() {

  @get:InputFiles
  @SkipWhenEmpty
  @get:PathSensitive(PathSensitivity.RELATIVE)
  abstract val protoSourceFiles: ConfigurableFileCollection

  @InputFiles
  @PathSensitive(PathSensitivity.RELATIVE)
  abstract val protoPathFiles: ConfigurableFileCollection

  // ...
}

(I thought SourceTask was needed for @SkipWhenEmpty but turns out it's not so it brings very little value compared to DefaultTask)

The nice bonus is that ConfigurableFileCollections are "lazy". They won't try to resolve their configurations until the task starts executing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants