Skip to content

Including JdkImageWorkaround in newer versions #419

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

Merged
merged 7 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.util.stream.Stream
* than Java 9. This normalizes out minor inconsequential differences between JDKs used to generate the
* custom runtime and improve cache hits between environments.
*/
@AndroidIssue(introducedIn = "7.1.0", fixedIn = ['7.4.0-alpha07'], link = "https://issuetracker.google.com/u/1/issues/234820480")
@AndroidIssue(introducedIn = "7.1.0", link = "https://issuetracker.google.com/u/1/issues/234820480")
class JdkImageWorkaround implements Workaround {
static final String WORKAROUND_ENABLED_PROPERTY = "org.gradle.android.cache-fix.JdkImageWorkaround.enabled"

Expand All @@ -63,15 +63,9 @@ class JdkImageWorkaround implements Workaround {
}
}

// Configuration for Old Variant API will drop in AGP 9. We will need to use a different
// approach to retrieve the variants using the new Variant API.
private static void applyToAllAndroidVariants(Project project, Closure<?> configureVariant) {
if (Versions.CURRENT_ANDROID_VERSION <= VersionNumber.parse("7.4.0-alpha01")) {
applyToAllAndroidVariantsWithOldVariantApi(project, configureVariant)
} else {
applyToAllAndroidVariantsWithNewVariantApi(project, configureVariant)
}
}

private static void applyToAllAndroidVariantsWithOldVariantApi(Project project, Closure<?> configureVariant) {
project.plugins.withId("com.android.application") {
def android = project.extensions.findByName("android")
android.unitTestVariants.all(configureVariant)
Expand All @@ -85,12 +79,6 @@ class JdkImageWorkaround implements Workaround {
}
}

private static void applyToAllAndroidVariantsWithNewVariantApi(Project project, Closure<?> configureVariant) {
def androidComponents = project.extensions.findByName("androidComponents")
def selector = androidComponents.selector()
androidComponents.onVariants(selector.all(), configureVariant)
}

static def applyRuntimeClasspathNormalization(Project project) {
project.normalization { handler ->
handler.runtimeClasspath {
Expand Down Expand Up @@ -174,6 +162,7 @@ class JdkImageWorkaround implements Workaround {
interface Parameters extends TransformParameters {
@Internal
Provider<Directory> getJavaHome()

void setJavaHome(Provider<Directory> javaHome)
}

Expand Down Expand Up @@ -240,7 +229,7 @@ class JdkImageWorkaround implements Workaround {

private static String serializeRequires(ModuleDescriptor.Requires requires) {
String requireString
if (! requires.compiledVersion().empty) {
if (!requires.compiledVersion().empty) {
requireString = requires.name() + " (@" + requires.compiledVersion() + ")"
} else {
requireString = requires.name()
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/org/gradle/android/WorkaroundTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class WorkaroundTest extends Specification {
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
where:
androidVersion | expectedWorkarounds
"8.0.0-alpha11" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask']
"7.4.0" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask']
"8.0.0-alpha11" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask', 'JdkImage']
"7.4.0" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask', 'JdkImage']
"7.3.1" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask', 'JdkImage']
"7.2.2" | ['MergeSourceSetFolders', 'RoomSchemaLocation', 'ZipMergingTask', 'JdkImage']
"7.1.3" | ['BundleLibraryClasses', 'CompileLibraryResources', 'DataBindingMergeDependencyArtifacts', 'LibraryJniLibs', 'MergeNativeLibs', 'MergeSourceSetFolders', 'RoomSchemaLocation', 'StripDebugSymbols', 'ZipMergingTask', 'JdkImage']
Expand Down