bamboo
09/23/2019, 8:26 PMScriptDependenciesResolver that reads the data from the given script resolver environment which can be configured via the -Xscript-resolver-environment command line argument. The custom resolver is setup via the ScriptTemplateDefinition annotation:
https://github.com/gradle/gradle/blob/6f683805c6b782b1eb91c01591aecabe6fe535fb/subprojects/kotlin-dsl/src/main/kotlin/org/gradle/kotlin/dsl/precompile/PrecompiledProjectScript.kt#L52-L54
My understanding is that it is NOT possible to mix the legacy ScriptTemplateDefinition annotation with the new KotlinScript one to get both, the dynamic implicit imports computed from the script resolver environment plus the implicit receivers from a custom compilationConfiguration setup.
So the question is then, does the experimental API allow for the list of default imports for a given script to be computed based on command line arguments passed to the compiler?
@KotlinScript(
compilationConfiguration = DynamicDefaultImportsConfiguration::class
// other settings
)
open class ScriptWithDynamicDefaultImports
object DynamicDefaultImportsConfiguration : ScriptCompilationConfiguration({
refineConfiguration {
beforeCompiling {
it.compilationConfiguration.with {
defaultImports(
// How to read arguments passed to the compiler from here?
TODO()
)
}.asSuccess()
}
}
})nastelaz
09/24/2019, 9:16 AMilya.chernikov
09/24/2019, 11:54 AMget(ScriptCompilationConfiguration.hostConfiguration)?.get(ScriptingHostConfiguration.getEnvironment)?.invoke()
but more importantly, since you can use your own host, you can add a new key to the compilation configuration and pass required parameters via it directly, without using command line.
But maybe it’s a bit too early for gradle to switch to the new API anyway: I had an intention to implement a refinement callback for “sections”, to remove necessity to use the lexer directly on your side. But if you’re eager to use new API, I can probably try to prioritize this task as well.bamboo
09/24/2019, 11:58 AMbamboo
09/24/2019, 11:58 AMbamboo
09/24/2019, 11:59 AMsince you can use your own host, you can add a new key to the compilation configuration and pass required parameters via it directly, without using command line.
bamboo
09/24/2019, 11:59 AMbamboo
09/24/2019, 12:00 PMilya.chernikov
09/24/2019, 12:08 PMbamboo
09/24/2019, 12:08 PMilya.chernikov
09/24/2019, 12:12 PMbamboo
09/24/2019, 12:14 PMcompileKotlin tasks somehow?ilya.chernikov
09/24/2019, 12:16 PMbamboo
09/24/2019, 12:16 PMbamboo
09/24/2019, 12:17 PMbamboo
09/24/2019, 12:18 PMcompileKotlin task which has its configuration augmented by the kotlin-dsl pluginbamboo
09/24/2019, 12:19 PMkotlin-dsl plugin adds the required script templates to the classpath and configures the script environment via freeCompilerArgsilya.chernikov
09/24/2019, 12:22 PMbamboo
09/24/2019, 12:27 PMbamboo
09/24/2019, 12:27 PMbamboo
09/24/2019, 12:28 PMbamboo
09/24/2019, 12:28 PMbamboo
09/24/2019, 12:29 PMbamboo
09/24/2019, 12:29 PMbamboo
09/24/2019, 12:30 PMilya.chernikov
09/24/2019, 12:30 PMilya.chernikov
09/24/2019, 12:35 PMkotlin-dsl extension to it.
So you can either continue to use “environment” hack, until we’ll come up with anything, or can create your own out-of-band data exchange.bamboo
09/24/2019, 12:37 PMbamboo
09/24/2019, 12:37 PMbamboo
09/24/2019, 12:38 PMbamboo
09/24/2019, 12:39 PMScriptDependenciesResolver to compute the classpathbamboo
09/24/2019, 12:39 PMilya.chernikov
09/24/2019, 12:39 PMbamboo
09/24/2019, 12:40 PMilya.chernikov
09/24/2019, 12:42 PMKotlinScript annotation, In this case the IDE support should work out of box.bamboo
09/24/2019, 12:42 PMbamboo
09/24/2019, 12:43 PMIn this case the IDE support should work out of box.
bamboo
09/24/2019, 12:44 PMScriptDependenciesResolver in that case would beilya.chernikov
09/24/2019, 12:44 PMbamboo
09/24/2019, 12:47 PM-script-templates compiler argument to tell exactly which templates should be used.ilya.chernikov
09/24/2019, 12:49 PMIt’s just not clear to me at this point what the replacement for theIn your example above, the block:in that case would beScriptDependenciesResolver
refineConfiguration {
beforeCompiling {
is one of the “resolvers” in the old API - it is a callback that is called by the compiler, so you can change compilation configuration according to your needs. So, e.g. now in this block you can add dependencies to the configuration.bamboo
09/24/2019, 12:49 PMbamboo
09/24/2019, 12:49 PMSo, e.g. now in this block you can add dependencies to the configuration.
bamboo
09/24/2019, 12:50 PMilya.chernikov
09/24/2019, 12:50 PMMaybe we should move the precompiled script templates to a separate module.The problem with distinction is IDE-specific, we can easily separate compilation, but in the IDE we have a single set of templates per project.
bamboo
09/24/2019, 12:50 PMbamboo
09/24/2019, 12:51 PMThe problem with distinction is IDE-specific, we can easily separate compilation, but in the IDE we have a single set of templates per project.
bamboo
09/24/2019, 12:51 PMbamboo
09/24/2019, 12:52 PMilya.chernikov
09/24/2019, 12:52 PMbamboo
09/24/2019, 12:52 PMbamboo
09/24/2019, 12:53 PMbamboo
09/24/2019, 12:53 PMbamboo
09/24/2019, 12:54 PMbamboo
09/24/2019, 12:54 PMilya.chernikov
09/24/2019, 1:03 PMbamboo
09/24/2019, 1:04 PMFor a moment we ignore (in the IDE) all dependencies that are coming from the configuration for scripts
bamboo
09/24/2019, 1:05 PMilya.chernikov
09/24/2019, 1:05 PMbamboo
09/24/2019, 1:06 PMbamboo
09/24/2019, 1:07 PMbamboo
09/24/2019, 1:07 PMilya.chernikov
09/24/2019, 1:08 PMbamboo
09/24/2019, 1:08 PMilya.chernikov
09/24/2019, 1:11 PMrefineConfiguration {
onSections("plugins", "dependencies") {
that would allow you to process sections of the scripts without using the lexer directly. What do you think about such an API?bamboo
09/24/2019, 1:18 PMplugins / buildscript / initscript sections as separate scriptsbamboo
09/24/2019, 1:19 PMilya.chernikov
09/24/2019, 1:20 PMonSections block, you need to execute another compiler for the section before continuing with the results.bamboo
09/24/2019, 1:20 PMilya.chernikov
09/24/2019, 1:21 PMbamboo
09/24/2019, 1:23 PMbamboo
09/24/2019, 1:24 PMbamboo
09/24/2019, 1:25 PMbamboo
09/24/2019, 1:25 PMbamboo
09/24/2019, 1:26 PMplugins { java }
java { }bamboo
09/24/2019, 1:26 PMplugins block before we can compile the rest of the scriptbamboo
09/24/2019, 1:27 PMProgram (that’s what we call this uniform façade to the scripts)bamboo
09/24/2019, 1:28 PMplugins section at this point because we know it needs to run every timebamboo
09/24/2019, 1:29 PMProgram that executes the precompiled plugins script and THEN compiles the rest after the plugins have been appliedbamboo
09/24/2019, 1:30 PMbamboo
09/24/2019, 1:30 PMilya.chernikov
09/24/2019, 1:42 PMonSections callback doesn’t fit your use case. I’ll think about it further. I still don’t like the fact that you’re using compiler internals. Maybe the old (and still unused) solution with the source-sections compiler plugin should be revived after all.bamboo
09/24/2019, 1:43 PM-script-templates anymore now that I changed from ScriptTemplateDefintion to KotlinScriptbamboo
09/24/2019, 1:43 PMbamboo
09/24/2019, 1:44 PMilya.chernikov
09/24/2019, 1:47 PMbamboo
09/24/2019, 1:47 PMbamboo
09/24/2019, 1:48 PMbamboo
09/24/2019, 1:48 PMilya.chernikov
09/24/2019, 1:48 PM-Pplugin:kotlin.scripting:script-definitions=...
or - better - use script definitions discovery mechanism.bamboo
10/07/2019, 5:18 PMKotlinScript annotation for compilation worked out great and Gradle 6.0 will ship with the new implicit receiver based script templates. Thanks again!bamboo
10/07/2019, 5:19 PMbamboo
10/07/2019, 5:22 PMilya.chernikov
10/08/2019, 6:20 AMilya.chernikov
10/08/2019, 6:21 AMbamboo
10/08/2019, 2:37 PM@KotlinScript based template yesterday but I didn’t manage to get it to see the baseClass(...) I gave the template, will continue to investigate it later.bamboo
10/08/2019, 2:37 PMbamboo
10/08/2019, 2:38 PM@ScriptTemplateDefinition to get the classpath and default imports but get the remaining settings (mainly implicitReceivers) from the `@KotlinScript`’s compilationConfiguration?ilya.chernikov
10/08/2019, 2:56 PMbamboo
10/08/2019, 3:10 PMbamboo
10/08/2019, 7:36 PMbamboo
10/08/2019, 7:37 PMbamboo
10/08/2019, 7:37 PMbamboo
10/08/2019, 8:00 PMannotationsForSamWithReceivers has no effect in IntelliJ, should it be supported already?bamboo
10/08/2019, 9:08 PMbamboo
10/08/2019, 9:09 PMbamboo
10/09/2019, 9:15 AMilya.chernikov
10/09/2019, 10:19 AMannotationsForSamWithReceivers - will check whether I can fix it quickly.
About the implicit receiver - I need to dig a bit deeper.bamboo
10/09/2019, 12:13 PMilya.chernikov
10/10/2019, 3:15 PMsamWithReceiver is a bit worse then I thought. I need some more time to implement required functionality for the new scripting API. I’ll try to do it as soon as possible, but I’m by far not sure if it is not already too late for 1.3.60.
Anyway, here is the issue to watch - https://youtrack.jetbrains.com/issue/KT-34294bamboo
10/10/2019, 4:07 PMbamboo
10/10/2019, 4:08 PMbamboo
10/10/2019, 4:09 PMbamboo
10/10/2019, 4:10 PMbamboo
10/10/2019, 4:10 PMbamboo
10/10/2019, 4:11 PMbamboo
10/10/2019, 4:11 PMilya.chernikov
10/10/2019, 4:36 PMilya.chernikov
10/14/2019, 3:13 PMilya.chernikov
10/14/2019, 3:14 PMTmpod
01/25/2020, 11:26 PMilya.chernikov
01/27/2020, 10:41 AMTmpod
01/27/2020, 10:47 AMTmpod
01/27/2020, 10:47 AMilya.chernikov
01/27/2020, 10:47 AMTmpod
01/27/2020, 10:49 AMTmpod
01/27/2020, 10:50 AMilya.chernikov
01/27/2020, 10:59 AMTmpod
02/11/2020, 7:14 PM