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

Use compileOnly for kotlin/agp plugins #648

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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

dependencies {
classpath libs.plugin.kotlin
classpath libs.plugin.android
classpath 'com.android.tools.build:gradle:7.3.1'

Choose a reason for hiding this comment

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

Not sure if this change was intented? 7.4-rc1 is in the toml.
/paparazzi/build.gradle and your new compileOnly still uses the 7.4 so you might get overridden.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling this was him testing the solution.

See the last classpath below and https://github.com/cashapp/paparazzi/blob/master/settings.gradle#L9 where that plugin is being replaced.

Copy link
Contributor

@TWiStErRob TWiStErRob Dec 15, 2022

Choose a reason for hiding this comment

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

I think I understand this more now. As I ran into an issue with this.

The the paparazzi-gradle-plugin can use the latest version, but for testing and building the paparazzi AAR an older version can be used.

@jrodbx I suggest splitting it into 3:

  • libs.plugin.android.build (for AAR build)
  • libs.plugin.android.test (for integration tests)
  • libs.plugin.android.api (for dependency)

The api should be behind a bit (stable), the build can be the latest alpha, and the test is the best compatible version.

classpath libs.plugin.versions
classpath libs.plugin.spotless

Expand Down
15 changes: 13 additions & 2 deletions paparazzi/paparazzi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ gradlePlugin {
}
}

configurations {
fixtureClasspath
}

tasks.named('pluginUnderTestMetadata').configure {
getPluginClasspath().from(configurations.fixtureClasspath)
}

dependencies {
compileOnly gradleApi()
implementation platform(libs.kotlin.bom)
implementation libs.plugin.kotlin
implementation libs.plugin.android
Copy link
Contributor

@TWiStErRob TWiStErRob Dec 15, 2022

Choose a reason for hiding this comment

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

please merge this PR, I can't use Android Studio Dolphin with 1.2.0-SNAPSHOT, because AS-D doesn't support 7.4:

The project is using an incompatible version (AGP 7.4.0-rc01) of the Android Gradle plugin. Latest supported version is AGP 7.3.1
See Android Studio & AGP compatibility options.

I'm not even sure of a workaround yet, because I'm using plugins {} so there's no classpath(...) { exclude }.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tried this, but it doesn't apply transitively and I don't want to list all modules:

buildscript {
	configurations.classpath.configure {
		resolutionStrategy { 
			force(libs.android.gradle)
			force(libs.android.lint.common)
    }

This crazy hack works 🤦‍♂️:

buildscript {
	configurations.classpath.configure {
		resolutionStrategy { 
			eachDependency { 
				if (requested.version == "30.4.0-rc01") {
					useVersion("30.3.1")
				}
				if (requested.version == "7.4.0-rc01") {
					useVersion("7.3.1")
				}
			}
		}
	}
}

compileOnly libs.plugin.android

implementation platform(libs.kotlin.bom)
implementation(libs.tools.sdkCommon) {
because "SymbolUtils.getPackageNameFromManifest removed in AGP 7.0. Replace?"
}

testImplementation libs.junit
testImplementation libs.truth

fixtureClasspath 'com.android.tools.build:gradle:7.3.1'
}

sourceSets {
Expand Down