-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from 2 commits
22a1121
68d6ea4
cf86322
fa66728
efb429f
339aaa9
a7e4569
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
|
@@ -53,16 +53,28 @@ class JdkImageWorkaround implements Workaround { | |
applyRuntimeClasspathNormalization(project) | ||
|
||
applyToAllAndroidVariants(project) { variant -> | ||
variant.javaCompileProvider.configure { JavaCompile task -> | ||
def jdkImageInput = getJdkImageInput(task) | ||
if (jdkImageInput != null) { | ||
setupExtractedJdkImageInputTransform(project, getJvmHome(task)) | ||
replaceCommandLineProvider(task, jdkImageInput) | ||
if (Versions.CURRENT_ANDROID_VERSION <= VersionNumber.parse("7.4.0-alpha01")) { | ||
variant.javaCompileProvider.configure { JavaCompile task -> | ||
jdkTransform(project, task) | ||
} | ||
} else { | ||
project.afterEvaluate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here correct me if I'm wrong, but my approach was based in: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above thread ^ |
||
project.tasks.withType(JavaCompile).configureEach { task -> | ||
jdkTransform(project, task) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void jdkTransform(Project project, JavaCompile task) { | ||
def jdkImageInput = getJdkImageInput(task) | ||
if (jdkImageInput != null) { | ||
setupExtractedJdkImageInputTransform(project, getJvmHome(task)) | ||
replaceCommandLineProvider(task, jdkImageInput) | ||
} | ||
} | ||
|
||
private static void applyToAllAndroidVariants(Project project, Closure<?> configureVariant) { | ||
if (Versions.CURRENT_ANDROID_VERSION <= VersionNumber.parse("7.4.0-alpha01")) { | ||
applyToAllAndroidVariantsWithOldVariantApi(project, configureVariant) | ||
|
@@ -86,14 +98,17 @@ 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) | ||
project.plugins.withId("com.android.base") { | ||
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 { | ||
it.ignore '**/java/lang/invoke/**' | ||
cdsap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it.metaInf { metaInfNormalization -> | ||
metaInfNormalization.ignoreAttribute('Implementation-Version') | ||
metaInfNormalization.ignoreAttribute('Implementation-Vendor') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a newer replacement for
variant.javaCompileProvider
in 7.4 + ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly nope, https://androidstudygroup.slack.com/archives/C03KKLGC2/p1591411391491800
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something like
variant.javaCompilation
like we do in theRoomWorkaround
?https://github.com/gradle/android-cache-fix-gradle-plugin/blob/main/src/main/groovy/org/gradle/android/workarounds/RoomSchemaLocationWorkaround.groovy#L116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried yesterday and same issue, at the time the variant is being processed we don't have agp
jdkImageInput
required to apply the workaround.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to extend the previous comment, in the previous AGP variant you have access to the Task Provider of Java task, because is lazy we can guarantee that the required ap options have been configured.
The new variant removes this functionality, in the case of the RoomWorkaround we don't require to have existing ap options because we are just inserting new argument provider in the variant block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@runningcode, following Xavier's comments, there is no replacement for
variant.javaCompileProvider
but we can still use the old API before is removed in AGP 9.I created new commit using the old API fa66728 and worked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good. Thanks for getting Xav's feedback there.