better handling for detecting complex precompiled configuration names #442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Given this dependencies block in a
.ktsbuild file for an Android module:dependencies { api(project(path = ":lib2")) }If we want to add:
androidTestDebugImplementation(project(path = ":lib1")), it'll be added with quotes to be invoked as a string extension:dependencies { "androidTestDebugImplementation"(project(path = ":lib1")) api(project(path = ":lib2")) }Instead, it should be this:
dependencies { androidTestDebugImplementation(project(path = ":lib1")) api(project(path = ":lib2")) }In short, the existing logic strips the configuration suffix (
-Implementationin this case) from the name, in order to get the source set (androidTestDebug). It then checks the source set name against the known default source sets added by this project's plugins (androidTest,debug,main,release, andtestsince this is Android), and if it matches one of those, then the configuration will be invoked without quotes.In this case, the source set of
androidTestDebugis still known at compile time, since it's just a combination ofandroidTestanddebug.This problem isn't unique to AGP. Other combined configurations like
anvilTestorkaptAndroidTestalso have this problem.The fix is recursion. After stripping away the java configuration suffix, check the source set. If it doesn't match a known one, try stripping away a known source set prefix and try the source set again. This only ever removes precompiled names, so if there's ever a match, then the whole thing is precompiled and no quotes are needed.