War 外掛擴充 Java 外掛,以新增組建 Web 應用程式 WAR 檔案的支援。它會停用 Java 外掛的預設 JAR 檔案產生,並新增預設 WAR 檔案工作。
用法
若要使用 War 外掛,請在建置指令碼中包含下列內容
plugins {
war
}
plugins {
id 'war'
}
專案配置
除了 標準 Java 專案配置 之外,War 外掛會新增
src/main/webapp
-
Web 應用程式來源
工作
War 外掛會新增和修改下列工作
war
— War-
相依於:
compile
組裝應用程式 WAR 檔案。
assemble
- 生命週期任務-
依賴於:
war
War 外掛會將下列依賴關係新增至 Java 外掛新增的任務中;

依賴關係管理
War 外掛會新增兩個依賴關係設定
providedCompile
-
此設定應使用於編譯時所需的依賴關係,但由 WAR 部署的環境提供。在此宣告的依賴關係因此會顯示在
main
和test
編譯類別路徑中。 providedRuntime
-
此設定應使用於執行時所需的依賴關係,但由 WAR 部署的環境提供。在此宣告的依賴關係僅會顯示在
main
和test
執行時類別路徑中。
請務必注意,這些 假設您將 如果您不想要這種遞迴行為,只要將您的 |
發布
components.web
-
SoftwareComponent 用於 發布
war
任務建立的生產 WAR。
慣例屬性 (已棄用)
webAppDirName
—String
-
預設值:
src/main/webapp
Web 應用程式來源目錄的名稱,相對於專案目錄。
webAppDir
— (唯讀)File
-
預設值:
$webAppDirName
,例如 src/main/webappWeb 應用程式來源目錄的路徑。
這些屬性由 WarPluginConvention 物件提供。
透過慣例屬性設定 war 任務已棄用。如果您需要設定 war
任務的預設值,請直接設定任務。如果您想要設定專案中所有 War
類型的任務,請使用 tasks.withType(War.class).configureEach(…)。
自訂
以下是包含最重要的自訂選項的範例
repositories {
mavenCentral()
}
dependencies {
providedCompile("javax.servlet:servlet-api:2.5")
}
tasks.war {
webAppDirectory = file("src/main/webapp")
from("src/rootContent") // adds a file-set to the root of the archive
webInf { from("src/additionalWebInf") } // adds a file-set to the WEB-INF dir.
webXml = file("src/someWeb.xml") // copies a file to WEB-INF/web.xml
}
repositories {
mavenCentral()
}
dependencies {
providedCompile "javax.servlet:servlet-api:2.5"
}
war {
webAppDirectory = file('src/main/webapp')
from 'src/rootContent' // adds a file-set to the root of the archive
webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF dir.
webXml = file('src/someWeb.xml') // copies a file to WEB-INF/web.xml
}
當然,可以設定不同的檔案集,並使用封閉函式來定義排除和包含。