我需要在 WAR 檔案的組裝程序中修改 Manifest 檔案。我需要在類路徑上添加所有檔案的串列,以避免java.io.IOException: CreateProcess error=206, The filename or extension is too long 當我想在 Windows 機器上執行這個 java 檔案時拋出例外。
直接在構建腳本中宣告此任務完成作業。
task pathingWar(type: War) {
getArchiveAppendix().set("pathing")
doFirst {
manifest {
attributes "Class-Path": sourceSets.main.runtimeClasspath.files.collect { project.uri(it) }.join(" ")
}
}
}
但是我想在buildSrc目錄中創建一個獨立的任務,如下面的代碼所示。War 是在名稱中使用路徑附錄創建的,但是即使在除錯任務執行時變數包含所需的值,檔案中也沒有其他Class-Path屬性。MANIFEST.MFclasspathFiles
class PathingWar extends War {
PathingWar() {
getArchiveAppendix().set("pathing")
}
@TaskAction
def setManifestTask() {
def classpathFiles = ((SourceSet)((SourceSetContainer) getProject().getExtensions().getByName("sourceSets"))
.getByName("main")).getRuntimeClasspath().getFiles().collect {project.uri(it)}.join(" ")
setManifest(getManifest().attributes(["Class-Path": classpathFiles]))
}
}
屬性不會設定到清單,在將邏輯從構建腳本轉換為自定義任務時我錯過了什么?
更新
經過進一步檢查,我發現執行setManifestTask()注釋時@TaskAction已經為時已晚。此時build/libs檔案夾下就生成了war 。我需要另一種配置清單的方法。我不知道使用哪種其他方法。
uj5u.com熱心網友回復:
我試圖在塊中設定 manifest Class-Path屬性,doFirst{}以便將它設定為第一個動作,并與原始腳本中的類似,但沒有成功。在執行關閉之前生成了仍然jardoFirst。
在閱讀以下答案https://stackoverflow.com/a/16413207/978302 后, 我明白我不應該覆寫 War 任務的功能。相反,我必須使用可用的輸入對其進行配置,結果將在幕后生成。
最終解決方案不包含任何定義的操作。僅附加配置:
- 檔案附錄
- 顯現
任務定義:
class PathingWar extends War {
PathingWar() {
getArchiveAppendix().set("pathing")
manifest {
def classpathFiles = ((SourceSet) ((SourceSetContainer) getProject().getExtensions().getByName("sourceSets"))
.getByName("main")).getRuntimeClasspath().getFiles().collect { project.uri(it) }.join(" ")
attributes "Class-Path": classpathFiles
}
}
}
順便說一句:我仍然不明白為什么腳本中定義的任務按預期作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/367233.html
上一篇:KotlinGradle-java.lang.NoClassDefFoundError:org/jetbrains/kotlin/konan/target/KonanTarget
下一篇:當我運行“npxreact-nativerun-ad”時,FreshReactNativeApp不會安裝在模擬器上
