Playframework Dependencies Management

在 Playframework 中,dependencies 是由 conf/dependencies.yml 檔案所管理。在這個檔案中,你可以設定相關的 dependencies 是來自不同的 repositories。像是在下圖中,我的 project 分別從 play 官方的 repository 吃了 play 和 fbgraph;另外其他的 dependencies 是吃我放在 local 的 jar file。在設定自己的 repositories 時,格式如下圖所示。

特別要注意的是,在 artifact 的部分,要放該 jar file 的絕對位置。像我就是放在該 project 下的 lib folder 中。

require:
- play
- play -> fbgraph 0.4
- provided -> qrgen 1.0
- provided -> zxing-core 1.7
- provided -> zxing-j2se 1.7
- provided -> google-api-translate-java 0.97
- provided -> flexjson 2.1
- provided -> restfb 1.6.9
- provided -> microsoft-translator-java-api-0.6.1-jar-with-dependencies 1.0
repositories:
- provided:
type: local
descriptor: "${application.path}/../[module]/conf/dependencies.yml"
artifact: "${application.path}/lib/[module]-[revision].jar"
contains:
- provided -> *
view raw gistfile1.yml hosted with ❤ by GitHub
在寫完 dependencies.yml 檔後,記得在 play command 中,輸入以下指令去安裝這些 dependencies 到你的專案中。

play deps
view raw gistfile1.yml hosted with ❤ by GitHub
如果你是用 ide 開發,請記得要再執行 ide 對應的指令,這樣你在 ide 中才能看到對應的 dependencies。像我是用 eclipse,就必須執行

play ec
view raw gistfile1.yml hosted with ❤ by GitHub

Share this post!

Bookmark and Share

0 意見: