Custom configuration within kotlin dsl

I am trying to convert a build.gradle into kotlin dsl. Earlier I had a custom configuration sourceset and configuration

       configurations { dashboard } 
       sourceSets { dashboard } 

and within dependecies block I had defined like this

    dependencies{
           dashboardImplementation 'org.slf4j:slf4j-simple:1.7.36'
           dashboardImplementation"com.grafana:dashboard-generator-core:0.0.1"
    
    }

and I had a custom task that was using these dependencies like this

    task generateDashboard(group: 'dashboard', description: 'generate dashboard json', type: JavaExec, dependsOn: "dashboardClasses") {
    	mainClass = "com.grafana.GenerateDashboard"
    	classpath = sourceSets.dashboard.runtimeClasspath
    }
    

The way I have made similar changes in kotlin dsl

 val dashboard by configurations.creating
    
 val dashboardSourceSet = sourceSets.create("dashboard")
dependencies{
    dashboard("org.slf4j:slf4j-simple:1.7.36")
    dashboard("com.grafana:dashboard-generator-core:0.0.1")
    
}

and a custom task as

     tasks.register<JavaExec>("generateDashboard") {
            group = "dashboard"
            dependsOn("dashboardClasses")
            main = "com.grafana.GenerateDashboard"
            classpath = sourceSets[dashboardSourceSet.name].runtimeClasspath
            
        }

However I get error when dependencies are not resolved for this task. Not sure why dependeNcies are not resolved with dashboard configuration

Because your code is majorly different.

In your Groovy version, you declare an unused configuration called dashboard and a sourc set called dashboard.
By creating the source set called dashboard it automatically creates the configurations dashboardImplementation, dashboardCompileOnly, and some others.
You declare your dependencies on dashboardImplementation which makes them appear on the source sets runtime classpath which you then use in your task.

In your Kotlin version it is slightly different.
You are still createing a configuration called dashboard and a source set called dashboard where the latter addes the same configurations as before.
But now you declare the dependencies on the dashboard configuration while you still use the runtime classpath of the dashboard soruce set which is absolutely unrelated to the dashboard configuration, bsides that you named them the same.

Actually your Kotlin code is a bit nearer to what you should have.
At least I assume that you do not have any code in that source set, then a source set makes no sense at all. A source set is for when you have own code in it.
And in both versions the dashboard configuration is considered legacy and deprecated as you have it consumable and resolvable (which is the default for backwards compatibility). It should be neither of the two if you just want to declare dependencies on it, it should be only consumable if you want downstream projects to consume it, if should be only resolvable if you want to resolve it.

Or if you have own classes, then the source set is what you want, but then the custom configuration is superfluous.

And btw. you should never use dependsOn except if on the left-hand side you have a lifecycle task.
For all other cases, properly model outputs and inputs, then you get the task dependencies that you need implicitly everywhere you need them.