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

Make AGP and KGP deps compileOnly #1105

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ZacSweers
Copy link
Contributor

Dependencies on other gradle plugins should be compileOnly dependencies, as it can accidentally impose the version paparazzi depends on rather than just use the one that the consuming project uses. For example – in our project, this transitive dep prevents us from testing newer AGP versions due to multiple versions appearing on the buildscript classpath.

image

Dependencies on other gradle plugins should be `compileOnly` dependencies, as it can accidentally impose the version paparazzi depends on rather than just use the one that the consuming project uses. For example – in our project, this transitive dep prevents us from testing newer AGP versions due to multiple versions appearing on the buildscript classpath.
Comment on lines 32 to 34
testImplementation libs.plugin.kotlin
testImplementation libs.plugin.android
testImplementation(libs.tools.sdkCommon) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Were you trying to replace the runtimeOnly part of the implementation with these to help Gradle TestKit?

If so, I hacked around this area of Gradle before, and got it working.

A likely cause for the CI failure is PluginUnderTestMetadata.getPluginClasspath, because the default only uses production runtime classpath.

Here's my solution: definition and usage.
(If you use this, you could probably ignore my version constraint usage, I needed it because I have AGP/KGP in the test matrix.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above should work more or less without any hacks, not sure why CI is failing. WIll look more later

@jrodbx
Copy link
Collaborator

jrodbx commented Sep 28, 2023

Dependencies on other gradle plugins should be compileOnly dependencies, as it can accidentally impose the version paparazzi depends on rather than just use the one that the consuming project uses. For example – in our project, this transitive dep prevents us from testing newer AGP versions due to multiple versions appearing on the buildscript classpath.

Is the newer plugin version check a new thing? We've definitely been able to pull in a newer AGP version on CashApp, with the risk of binary incompatibilities resulting in Paparazzi crashes, but that's different from your error message.

Re: the premise of compileOnly, I've previously attempted such (even consulting @autonomousapps given his success in having a test matrix in dependency-analysis-gradle-plugin), but @JakeWharton and I were of the opinion that it probably wasn't worth the maintenance burden, given AGP's dev cycle. Not opposed to it, if successful though.

@jrodbx jrodbx closed this Sep 28, 2023
@jrodbx jrodbx reopened this Sep 28, 2023
@jrodbx
Copy link
Collaborator

jrodbx commented Sep 28, 2023

accidentally hit "Close with comment", just meant to "Comment". My bad.

@ZacSweers
Copy link
Contributor Author

Is the newer plugin version check a new thing?

It's not a check, it's just how gradle and classloading work. It's a first-one-wins policy in many cases due to the hierarchical nature of gradle and generally just good plugin hygiene to not impose other plugin versions transitively. Things get tricky when you start assuming things about versions when a dependency appears sooner in that hierarchy (i.e. such as settings.gradle classpath) and later projects assume their dependency will win or be resolved with others.

Comment on lines +23 to +24
/paparazzi-gradle-plugin/src/test/projects/rerun-resource-change/src/main/res/values/colors.xml
/paparazzi-gradle-plugin/src/test/projects/rerun-asset-change/src/main/assets/secret.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were getting generated as untracked files when I ran tests locally, so opportunistically adding them here

Comment on lines +29 to +38
Configuration addTestPlugin = configurations.create("addTestPlugin")

configurations {
testImplementation.extendsFrom(addTestPlugin)
}

tasks.pluginUnderTestMetadata {
// make sure the test can access plugins for coordination.
pluginClasspath.from(addTestPlugin)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This pattern is what we use in Keeper to test against non-bundled KGP/AGP deps

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

Successfully merging this pull request may close these issues.

3 participants