Avoid duplication between similar Gradle tasks?

后端 未结 4 1067
醉话见心
醉话见心 2021-02-02 10:47

It there any way to avoid duplication in configuration between two similar tasks of the same type?

For example, I\'d like to create a debugSomething task, w

4条回答
  •  一个人的身影
    2021-02-02 11:07

    I've been searching for something similar with a difference that I don't want to share the config among all the tasks of the same type, but only for some of them.

    I've tried something like stated in the accepted answer, it wasn't working well though. I'll try again then.

    As I've got here, I don't mind to share, there is (at least now) a better, Gradle's built-in way to achieve the thing which was asked here. It goes like:

    tasks.withType(JavaExec) {
        jvmArgs "-Xmx1024m", "-XX:MaxPermSize=128m"
        main = "com.some.Main"
        classpath = sourceSets.main.runtimeClasspath
    }
    

    This way all the tasks of JavaExec type will receive the default config which can obviously be altered by any specific task of the same type.

提交回复
热议问题