Avoid duplication between similar Gradle tasks?

后端 未结 4 1064
醉话见心
醉话见心 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:16

    I've found that using the Task.configure method is very helpful for centralizing logic like this.

    I haven't tested it, but in your case this might look like this:

    def commonSomething = {
        main = "com.some.Main"
        classpath = sourceSets.main.runtimeClasspath
        jvmArgs "-Xmx1024m", "-XX:MaxPermSize=128m"
    }
    
    task runSomething(dependsOn: jar, type: JavaExec, group: "Run") {
        configure commonSomething
    }
    
    task debugSomething(dependsOn: jar, type: JavaExec, group: "Run") {
        configure commonSomething
        jvmArgs ...add debug arguments...
    }
    

提交回复
热议问题