Premise: I don’t strictly need that, I’m just expe...
# gradle
d
Premise: I don’t strictly need that, I’m just experimenting the gradle-dsl + buildSrc I got this in my Dependencies.kt:
Copy code
class Classpath( scope: ScriptHandlerScope ) {
    val dependencies: DependencyHandlerScope.() -> Unit = {
        scope.run {
            classpath( kotlin("gradle-plugin", Versions.kotlin))
            classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
            classpath("com.android.tools.build:gradle:3.3.0")
            classpath("com.squareup.sqldelight:gradle-plugin:${Versions.sqldelight}")
        }
    }
}
And this in my build.gradle.kts:
Copy code
buildscript {
    repositories( Repositories.all )
    dependencies( Classpath(this ).dependencies )
}
Is there something wrong here? Sync is running successfully, but I got the warning above my
kts
file:
build configuration failed, using previous dependencies, run 'gradle tasks' for more information
which is not true, since that doesn’t give me more info 😄
g
Did you try to run build from cpmmand line? does it work or not?
just a side note, don’t think that you need class in this case, a function with ScriptHandlerScope argument should be enough
d
I do, because
classpath
is an extension function of
DependencyHandler
, declared inside
ScriptHandlerScope
BUILD SUCCESSFUL in 1m 13s
Only a warning
Unsupported Kotlin plugin version.
I guess because of the deprecated
kotlin-dsl
plugin on 1.3.20 ( I’m googling for a solution for that 😄 )
g
Why not just
Copy code
fun DependencyHandlerScope.dependencies(scope: ScriptHandlerScope) {
        scope.run {
            classpath( kotlin("gradle-plugin", Versions.kotlin))
            classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
            classpath("com.android.tools.build:gradle:3.3.0")
            classpath("com.squareup.sqldelight:gradle-plugin:${Versions.sqldelight}")
        }
    }
Copy code
dependencies( Classpath(this ).dependencies(this))
d
Yes, that could be better, just trying with the “common pattern” for buildSrc, since I seen nested objects don’t work, for instance, but I guess my warning would persist. I’mma try to invalidate the cache, just in case
g
nested objects don’t work, for instance
What do you mean?
d
I’ve tried that, but Kotlin and Android are not resolved
Copy code
object Versions {
    ...
}

object Libs {
    object Kotlin {
        ...
    }
    object Android {
        ....
    }
}
g
This works.
Maybe you just have some tooling problem, but it’s valid syntax
and we even use it in our buildSrc
d
maybe something wrong about that:
Copy code
plugins {
    `kotlin-dsl`
}

repositories {
    jcenter()
}
g
@Davide Giuseppe Farella https://pl.kotl.in/S1mcrNh7V
no, nothing wrong
Do you have some sample project?
d
Yes, I know that would work normally, just don’t know about buildSrc
g
buildSrc is just Kotlin code, not even scripting
d
Imma publish on github, just a new project
g
And do you have example where nested object doesn’t work?
d
Imma add it now
Damn, that worked now 😄 so embaracing 😄 Idk what happened 🙈 Also tried some days ago on a multiplaform project
g
buildSrc is just a Kotlin code, so everything what works for Kotlin code should work there
excluding some bugs (I remember problems with nested subclasses resolution in IDEA a few months ago, but now everything should work and it was tooling only problem)
d
before I tried with Libs.Android.test = “bla.blablabla”, everything ok but just NOT resolved “bla.bla…” obviously, now I tried with a real deps and got that ( sync successfully )
message has been deleted
g
I didn’t get what you mean
Does build is successful?
You see, you have failed syncronization
so nothing is syncronized
d
appcompat is not resolved ( IDE says )
Yes, that warning is what I was talking about 😛
g
Yes
it means that sync is failed
see logs
Most probably you have some error in your buildSrc or your configs
d
Just noticed those errors in my sync ( even if successfully )
Copy code
[TAG] Failed to resolve variable '${project.groupId}'	
[TAG] Failed to resolve variable '${project.version}'	
[TAG] Failed to resolve variable '${version.asm}'	
[TAG] Failed to resolve variable '${version.junit}'	
[TAG] Failed to resolve variable '${version.mockito}'	
[TAG] Failed to resolve variable '${version.asm}'	
[TAG] Failed to resolve variable '${project.groupId}'	
[TAG] Failed to resolve variable '${project.version}'	
[TAG] Failed to resolve variable '${version.junit}'	
[TAG] Failed to resolve variable '${version.mockito}'
g
no, this is not related
AS is pretty bad in reporting configuration time errors
you said that build is successful, are you sure about this?
d
Yep, I’ve also wondered that 😕 it’s just a new project, I don’t have any files, out of that gradle ones 😄
message has been deleted
g
But you change gradle files, so apparently you have changes
I tried to build you project, and there is error in root build.gradle.kts
d
Also my properties in Dependencies.kt seems unused, even if they’not.
g
with pretty clear description
d
yes, I was in a middle of a change 😄
updated right now
that was about that
repositories
in Dependencies.kt
g
Yes
d
message has been deleted
Are you in the same situation?
g
Did you update your repo?
d
what you mean? 🙈
Ah sorry, yes
g
I mean to let me try, does I have problem with sync or not
d
It’s updated
I was thinking about the project’s repositories 😄
g
I imported your project and sync is successful (no
build configuration failed
message) and nested objects just work. So probably some problem with IDE caches or something like that
message has been deleted
d
As or IntelliJ? Version?
I always got weird problem when go beta -> stable :D\
g
AS 3.3
sorry, this is version with nested object
d
Same version… I’mma try to fresh install 😕
Thanks you very much for your time 🍻
👍 1
g
I believe reimport of the project will help
d
Oh ok, that would save me time 🙂
g
But careful with “Reimport project” function in AS, it creates an empty build.gradle file
d
I’ve just removed from my project and imported from folder, as fresh project. Seems ok. The only detail: cmd+b on my dependency in build.gradle.kts keep pointing to the compiled file
Libs.class
so the properties on Dependencies.kt are still marked as unused, it that normal? I didn’t have this behaviour on IntelliJ
Just for info, not that I care, unless it won’t lead to other issues 🙂
g
Yeah, unfortunately tooling is not perfect, especially with AS which doesn’t have all the latest fixes from IDEA
d
Gotcha 👍
g
also, check that you use Kotlin IDE plugin 1.3.20, there are some fixes for kotlin-dsl
👍 1