-
Notifications
You must be signed in to change notification settings - Fork 15
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
Remove usages of afterEvaluate #120
Comments
I tried something locally (the code snippets use extensions I added but pls read as pseudocode) The goal is to have a full picture of the module at the time when the metalava plugin needs it, what I did:
val support = objects.listProperty<SupportedPlugin>()
withJavaPlugin { support.add(Java(java)) } // not java-library, just java, which is also applied by kotlin-jvm for instance
withAnyKotlinPlugin { support.add(Kotlin(kotlin)) } // any of the ff kotlin plugins: kotlin-jvm, -android, -multiplatform
withAndroidLibraryPlugin { support.add(AndroidLibrary(androidComponents)) } // android-library only
afterEvaluate {
if (support.get().isEmpty()) throw GradleException("No supported metalava plugins found.")
}
return SupportedPlugins(support)
withJavaLibraryPlugin { // java-library
// necessary to after evaluate here so we are sure tasks are created after user code
// eg. in case new source sets are added
afterEvaluate {
println("Java library. ${java.sourceSets.toList()} $support")
}
}
withAndroidLibraryPlugin { // android-library
androidComponents {
// Variants are created after buildscript evaluation so we can safely iterate & configure each one
// Android has its own concept of sourceSets which can deduced from the variant names / buildtypes / flavors.
onVariants { variant ->
println("Android variant: ${variant.name}. $support")
}
}
}
withAnyKotlinPlugin { // both single & multiplatform
/*
Targets provide a good entry point for Multiplatform projects and for single-platform kotlin projects,
the target is implicit, so the abstraction still works.
Each target has a list of compilations which include variants of the main and test sourceSets.
*/
kotlin.configureEachTargetCompilation {
println("Kotlin target: ${target.targetName.ifEmpty { "{target}" }}/$name, $kotlinSourceSets. $support")
}
} The result:
|
The cases that need to be supported include
Currently, this plugin creates a single task set (task set represents the set of check & generate metalva tasks) for projects that do not apply android, and a task set per variant for android projects. This was okay when users where asked to manually specify source folders, the responsibility was on the users to figure out how to add the correct sourceSets, but this does not work with this plugin's automatic configuration and in fact its confusing in the case where kotlin is applied with other plugins (most especially kmp) I think it would be better to explicitly define what is supported (for kmp, are all targets supported or just the jvm & android targets), and in the kotlin cases, work with targets/compilations & not just sourceSets. |
As mentioned in #117, this plugin should be reacting to other plugins as they're applied, instead of using a nondeterministic mechanism to wait until it thinks relevant plugins are applied.
The text was updated successfully, but these errors were encountered: