Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

"tasks.withType" that do not extend "*Task" such as "JavaForkOptions" #439

Closed
jaredsburrows opened this issue Jul 22, 2017 · 4 comments
Closed

Comments

@jaredsburrows
Copy link
Contributor

jaredsburrows commented Jul 22, 2017

This works in Groovy DSL, build.gradle:

// Prevent forked processes from stealing focus (on MacOS at least)
tasks.withType(JavaForkOptions) {
  // should improve memory on a 64bit JVM
  jvmArgs "-XX:+UseCompressedOops"
  // should avoid GradleWorkerMain to steal focus
  jvmArgs "-Djava.awt.headless=true"
  jvmArgs "-Dapple.awt.UIElement=true"
}

This fails to work in Kotlin DSL, build.gradle.kts:

// Prevent forked processes from stealing focus (on MacOS at least)
tasks.withType<JavaForkOptions> {
  // should improve memory on a 64bit JVM
  jvmArgs "-XX:+UseCompressedOops"
  // should avoid GradleWorkerMain to steal focus
  jvmArgs "-Djava.awt.headless=true"
  jvmArgs "-Dapple.awt.UIElement=true"
}

Since JavaForkOptions does not extend *Task, it will not work.

@jaredsburrows
Copy link
Contributor Author

@bamboo Do you know how to configure this?

@eskatos
Copy link
Member

eskatos commented Jul 25, 2017

tasks is a container of Task elements, it's withType() method only accept Task subtypes.
Your snippet works in Groovy as it is quite lax on type checking.

This should do using the Kotlin DSL:

tasks.all {
    when(this) {
        is JavaForkOptions -> {
            // should improve memory on a 64bit JVM
            jvmArgs("-XX:+UseCompressedOops")
            // should avoid GradleWorkerMain to steal focus
            jvmArgs("-Djava.awt.headless=true")
            jvmArgs("-Dapple.awt.UIElement=true")
        }
    }
}

@jaredsburrows
Copy link
Contributor Author

@eskatos Thank you!

@sschuberth
Copy link

Is there a way to do this in a more elegant way when limiting ourselves to run tasks specifically?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants