javascript
JRebel适用于Gradle Spring Boot应用程序
關(guān)于如何將JRebel添加到使用Gradle作為構(gòu)建工具的Spring Boot應(yīng)用程序中,有一些文檔 。 它是基本的,但是效果很好。
您所要做的就是在build.gradle中添加幾行:
if (project.hasProperty('rebelAgent')) {bootRun.jvmArgs += rebelAgent }然后在gradle.properties中設(shè)置屬性:
rebelAgent=-agentpath:[path/to/JRebel library]但是,有幾種方法可以對此進行改進。
使JRebel成為可選
例如,如果每次使用' bootRun'啟動應(yīng)用程序時都不總是想要JRebel怎么辦? 像Intellij IDEA這樣的IDE的JRebel插件足夠聰明,可以讓您選擇是否使用JRebel來運行您的應(yīng)用程序
這樣做有幾種方法,但是一種方法是在可選任務(wù)中添加JRebel啟動配置。
task addRebelAgent << {if (project.hasProperty('rebelAgent')) {bootRun.jvmArgs += rebelAgent}elseprintln 'rebelAgent property not found' }task rebelRun(dependsOn: ['addRebelAgent', 'bootRun'])現(xiàn)在運行“ bootRun”將正常啟動該應(yīng)用程序,如果您想要JRebel,請改用“ rebelRun”任務(wù)。 如果'rebelAgent'屬性不可用,我還添加了一條調(diào)試消息。
另一種方法是將可選屬性傳遞給“ bootRun”任務(wù),以用作是否添加JRebel的標志。
if (project.hasProperty('rebelAgent') &&project.hasProperty('addJRebel')) {bootRun.jvmArgs += rebelAgent }然后,要使用JRebel,您只需添加多余的屬性。
gradle bootRun -PaddJRebel = true
尋找叛軍基地
在屬性文件中放置JRebel庫的路徑以用作代理,可使多個開發(fā)人員擁有自己的版本。 但是,路徑仍然是硬編碼的,如果可能的話,應(yīng)該避免這種情況。
指定路徑的另一種方法是使用系統(tǒng)環(huán)境變量來指向JRebel的安裝位置。 JetBrains建議使用REBEL_BASE 。 設(shè)置完成后,您可以通過多種方式使用環(huán)境變量,例如Gradle構(gòu)建文件,命令行,構(gòu)建腳本等。
這是一個示例,該示例使用了我之前在Windows 64計算機上使用的其他“ addRebelAgent”任務(wù)。
task addRebelAgent << {project.ext {rebelAgent = "-agentpath:${System.env.REBEL_BASE}${rebelLibPath}"}if (project.hasProperty('rebelAgent')) {bootRun.jvmArgs += rebelAgent}elseprintln 'rebelAgent property not found' }task rebelRun(dependsOn: ['addRebelAgent', 'bootRun'])在gradle.properties中,我從JRebel安裝位置指定了到代理庫的路徑。
rebelLibPath=\\lib\\jrebel64.dll我在這里所做的只是在REBEL_BASE環(huán)境變量的'rebelAgent'屬性中構(gòu)建路徑,以及另一個指定庫的內(nèi)部路徑的屬性。
rebelAgent = "-agentpath:${System.env.REBEL_BASE}${rebelLibPath}"翻譯自: https://www.javacodegeeks.com/2018/02/jrebel-gradle-spring-boot-app.html
總結(jié)
以上是生活随笔為你收集整理的JRebel适用于Gradle Spring Boot应用程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 当枪使是什么意思 当枪使的含义
- 下一篇: 101英语怎么读 101英语是什么