Hi all, long-time lurker, first-time poster. I’m ...
# gradle
t
Hi all, long-time lurker, first-time poster. I’m trying to use SpringSecurity’s kotlin DSL to configure my SecurityConfig for my hobby project. Running on Gradle 6.8. Using a clean architecture style multi-module set-up. Where I made shared dependencies (i.e. spring-boot, kotlin) available using a
buildSrc
module, with the
kotlin-dsl
convention plugin (as is suggested as a best practice according to the Gradle Docs, but I’ve had quite a bit of issues with these convention plugin scripts not compiling in IntelliJ etc). I’m using IntelliJ as my IDE, but a normal
gradlew clean build
fails on the same compilation error.
Copy code
e: .../SecurityConfig.kt: (15, 9): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
The
http: HttpSecurity
function argument to my
WebSecurityConfigurerAdapter
impl doesn’t seem to support a configuration lambda. Any help is appreciated. 🙏
My buildSrc/build.gradle.kts:
Copy code
plugins {
    `kotlin-dsl`
}

repositories {
    gradlePluginPortal()
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10")
    implementation("org.jetbrains.kotlin.plugin.spring:org.jetbrains.kotlin.plugin.spring.gradle.plugin:1.4.21")
    implementation("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
    implementation("io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.11.RELEASE")
    implementation("com.github.jengelman.gradle.plugins:shadow:6.1.0")
}
My rest-api adapter module’s build.gradle.kts:
Copy code
plugins {
    id("scrambledeggs.kotlin.library-conventions")
    id("scrambledeggs.spring.web-conventions")
    id("scrambledeggs.spring.security-conventions")
}

dependencies {
    api(project(":infra"))
    api(project(":domain:core-api"))
    api(project(":domain:leaderboards-api"))
}
If I run a
./gradlew adapter:rest-api:dependencies
I do notice that the
spring-security-config
dependency is there:
Copy code
+--- org.springframework.boot:spring-boot-starter-security -> 2.5.1
|    +--- org.springframework.boot:spring-boot-starter:2.5.1 (*)
|    +--- org.springframework:spring-aop:5.3.8 (*)
|    +--- org.springframework.security:spring-security-config:5.5.0
This contains a kotlin class
HttpSecurityDsl
along with an extension function that’s supposed to activate the Dsl, but for some reason won’t in my IntelliJ, nor in my gradle compile.
After I discovered this, suddenly it did start compiling, when I explicitly referenced
http.invoke
I want to cry. 😭😭😭 This just took me >3 hours.
k
could you show what was working what not?
t
Not sure if it will be very helpful but here’s last night’s stream where I was messing around with it until I finally gave up “on stream” and continued off stream to fix it. Best effort at the moment. Do you want me to try and reproduce it?