KT-41425 Project can not be launched with Gradle runner

93a82060 introduced support of "delegate to Gradle" for Gradle-Kotlin.
This commit fixes an issue known as "Could not get unknown property
'sourceSets' for root project".
This commit is contained in:
Andrei Klunnyi
2020-08-26 15:12:20 +02:00
parent f57f920dc0
commit 5cf76aa950
@@ -170,33 +170,35 @@ class KotlinGradleAppEnvProvider : GradleExecutionEnvironmentProvider {
allprojects { allprojects {
afterEvaluate { project -> afterEvaluate { project ->
def overwrite = project.tasks.findByName(runAppTaskName) != null if (project.path == gradlePath) {
project.tasks.create(name: runAppTaskName, overwrite: overwrite, type: JavaExec) { def overwrite = project.tasks.findByName(runAppTaskName) != null
if (javaExePath) executable = javaExePath project.tasks.create(name: runAppTaskName, overwrite: overwrite, type: JavaExec) {
if (project.pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform")) { if (javaExePath) executable = javaExePath
project.kotlin.targets.each { target -> if (project.pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
target.compilations.each { compilation -> project.kotlin.targets.each { target ->
if (compilation.defaultSourceSetName == sourceSetName) { target.compilations.each { compilation ->
classpath = compilation.output.allOutputs + compilation.runtimeDependencyFiles if (compilation.defaultSourceSetName == sourceSetName) {
classpath = compilation.output.allOutputs + compilation.runtimeDependencyFiles
}
} }
} }
} else {
classpath = project.sourceSets[sourceSetName].runtimeClasspath
} }
} else {
classpath = project.sourceSets[sourceSetName].runtimeClasspath main = mainClass
} $argsString
if(_workingDir) workingDir = _workingDir
main = mainClass standardInput = System.in
$argsString if(javaModuleName) {
if(_workingDir) workingDir = _workingDir inputs.property('moduleName', javaModuleName)
standardInput = System.in doFirst {
if(javaModuleName) { jvmArgs += [
inputs.property('moduleName', javaModuleName) '--module-path', classpath.asPath,
doFirst { '--module', javaModuleName + '/' + mainClass
jvmArgs += [ ]
'--module-path', classpath.asPath, classpath = files()
'--module', javaModuleName + '/' + mainClass }
]
classpath = files()
} }
} }
} }