Adding classpath entries using Gradle's Application plugin

后端 未结 5 505
攒了一身酷
攒了一身酷 2021-02-01 18:57

I\'m using Gradle\'s Application plugin to generate the install for a standalone java application. I have a configuration file I need to put on the classpath but I can\'t seem t

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 19:35

    This isn't a particularly good answer to your question, but I've found a few instances where the startScripts task doesn't quite yet have the flexibility we need.

    I've worked around a couple of these instances by editing the file contents directly... not exactly taking advantage of Gradle's great model and not particularly recommended, but at least shows off how flexible Gradle is!

    So you could hack something into the classpath like this:

    tasks.startScripts {
      doLast {
        def scriptFile = file "${outputDir}/${applicationName}"
        scriptFile.text = scriptFile.text.replace('CLASSPATH=$APP_HOME/lib', 'CLASSPATH=$APP_HOME/conf/:$APP_HOME/lib')
      }
    }
    

    Be aware of breaking the start script's platform independence when doing this.

提交回复
热议问题