-
Notifications
You must be signed in to change notification settings - Fork 434
unable to apply gradle/kotlin script #814
Comments
The same thing even without inter-modules file linking. Just have a main Any ETA or workaround on this? |
Possibly related to #601 |
#601 more about syntax highlight and IDE support, in this case gradle not even builds these scripts :( |
You might want to try this instead:
|
IntelliJ marks the file as faulty: I can use the file standalone using the shell: However when including it exception seems to be the same:
There is a note in the plugin documentation "If you would like to use this plugin from a build file which is not the main build file you must apply/use it like this:..." (https://github.com/bmuschko/gradle-docker-plugin) I interpret it that I should use the first form to include the plugin (like in my example) |
For sanity's sake, can you do me a favor and try with version I know that this works for me: import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.image.DockerPullImage
import com.bmuschko.gradle.docker.tasks.DockerVersion
import java.net.Socket
buildscript {
dependencies {
classpath("com.bmuschko:gradle-docker-plugin:3.2.0")
}
}
apply {
plugin("com.bmuschko.docker-remote-api")
}
fun isPortInUse(hostName: String, portNumber: Int) = try {
Socket(hostName, portNumber).close()
true
} catch (exception: Exception) {
false
}
val isRabbitmqRunning = isPortInUse("localhost", 5672)
fun Task.skipIfRabbitmqRunning() {
onlyIf {
!isRabbitmqRunning
}
}
/**
* Workaround for:
* - https://github.com/gradle/kotlin-dsl/issues/593
* - https://github.com/bmuschko/gradle-docker-plugin/issues/495
*/
class CustomKotlinClosure1<in T : Any?, V : Any>(
val function: T.() -> V?,
owner: Any? = null,
thisObject: Any? = null
) : groovy.lang.Closure<V?>(owner, thisObject) {
@Suppress("unused") // to be called dynamically by Groovy
fun doCall(it: T): V? = it.function()
}
// skipDocker is not included in this example, it's my own code.
fun Task.skipIfSkipDockerSpecified() {
onlyIf { !skipDocker }
}
val getDockerVersion = task<DockerVersion>("getDockerVersion") {
onError = CustomKotlinClosure1<Exception?, Unit>({
if (this == null) {
// TODO: Fix after this is resolved: https://github.com/bmuschko/gradle-docker-plugin/issues/490
return@CustomKotlinClosure1 Unit
}
val message = "Docker is not installed or is not running."
if (skipDocker) {
logger.error("$message Skipping Docker dependent tasks.")
} else {
throw GradleException("$message To skip Docker tasks run with -P$skipDockerPropertyName flag.")
}
})
}
val pullRabbitmqContainer = task<DockerPullImage>("pullRabbitmq") {
tag = "latest"
repository = "rabbitmq"
dependsOn(getDockerVersion)
skipIfRabbitmqRunning()
skipIfSkipDockerSpecified()
}
val createRabbitmqContainer = task<DockerCreateContainer>("createRabbitmq") {
dependsOn(pullRabbitmqContainer)
portBindings = listOf("5672:5672")
targetImageId {
pullRabbitmqContainer.run { if (tag != null) "$repository:$tag" else repository }
}
skipIfRabbitmqRunning()
skipIfSkipDockerSpecified()
}
val startRabbitmqContainer = task<DockerStartContainer>("startRabbitmq") {
dependsOn(createRabbitmqContainer)
targetContainerId { createRabbitmqContainer.containerId }
skipIfRabbitmqRunning()
skipIfSkipDockerSpecified()
}
val removeRabbitmqContainer = task<DockerRemoveContainer>("removeRabbitmq") {
onlyIf { createRabbitmqContainer.containerId != null }
targetContainerId { createRabbitmqContainer.containerId }
}
val stopRabbitmqContainer = task<DockerStopContainer>("stopRabbitmq") {
onlyIf { createRabbitmqContainer.containerId != null }
targetContainerId { createRabbitmqContainer.containerId }
finalizedBy(removeRabbitmqContainer)
} |
sure. again the script works standalone but cannot be imported into another script ... |
@abendt You may want to try putting this in your
|
I get the same 4 script compilation errors. |
@abendt buildscript {
dependencies {
classpath("com.bmuschko:gradle-docker-plugin:3.2.0")
}
}
apply {
from("docker2.gradle.kts")
} And in your // Some imports
apply {
// some plugin
} And you still get compilation issues? |
@JLLeitschuh yes, i still get compilation issues. I updated my demo project: https://github.com/abendt/gradle-docker-modularity
|
@JLLeitschuh, no, the |
Thanks @bamboo I couldn't find the issue but I thought this was unsupported currently. Thanks. |
Any ETA on this? Groovy scripts allows using imports from plugins that applies in main build.gradle, but kts not. That's causes a lot of problems migrating groovy scripts to kts. |
Expected Behavior
I want to import (apply) a gradle/kotlin script that contains shared logic into a given gradle/kotlin script.
Current Behavior
works, if the imported script is groovy
fails after i migrated the imported script to kotlin
the imported script works standalone
Context
in a multimodule build I have some shared logic to configure/start/stop some docker containers.
some of the modules apply the shared script.
Steps to Reproduce (for bugs)
I setup a stripped down example
https://github.com/abendt/gradle-docker-modularity
cd module1; gw dockerVersion
module1 uses the groovy version of the script ../docker.gradle. the task dockerVersion comes from the shared script.
cd module2; gw dockerVersion
module2 uses the kotlin version of the script ../docker2.gradle.kts
module2 fails with:
However its possible to invoke the included script directly so it seems to be correct:
gw -b ../docker2.gradle.kts dockerVersion
Also the script is shown to be faulty in IntelliJ
Your Environment
Gradle:
gw --version
IntelliJ:
The text was updated successfully, but these errors were encountered: