我試圖通過將我自己的自定義 java 檔案添加到類路徑中來遵循這一點
https://github.com/gigaSproule/swagger-gradle-plugin#model-converters
這在上面的示例中顯示
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.custom:model-converter:1.0.0' } } ... swagger { apiSource { ... modelConverters = [ 'com.custom.model.Converter' ] } }
這是我的代碼
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.test.app.profile.component.MyOpenApiCustomiser:1.0.0")
}
}
swagger {
apiSource {
...
modelConverters = [ 'com.test.app.profile.component.MyOpenApiCustomiser' ]
}
}
這是我得到的錯誤
A problem occurred configuring root project 'profile'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.test.app.profile.component.MyOpenApiCustomiser:1.0.0:.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
我嘗試洗掉1.0.0
Caused by: org.gradle.api.IllegalDependencyNotation: Supplied String module notation 'com.test.app.profile.component.MyOpenApiCustomiser' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'
不知道如何讓我的構建腳本在我的 Spring Boot 應用程式中使用 MyOpenApiCustomiser 有沒有其他方法或如何解決這個問題?
uj5u.com熱心網友回復:
塊中給出的classpath依賴項buildscript.dependencies {}需要是外部庫,在標準組中給出:modulde:version表示法;在來自 github 專案的示例中,它是“com.custom:model-converter:1.0.0”(這是一個“假”庫,在 maven 中央存盤庫中并不存在,這只是一個示例)
在您的情況下,您似乎嘗試將您的類MyOpenApiCustomiser稱為 classpath library ,但它不起作用。它需要是一個真正的圖書館。
如果你想使用你自己的轉換器,你需要在另一個庫/模塊中實作它,將它發布到一個私有存盤庫,然后在你的 buildscript 類路徑中使用它。
另一種更簡單的方法是將這個轉換器實作為buildSrc 專案中的一個類:然后這些類將自動在您的構建腳本類路徑中可用,您可以在apiSource配置中使用它。
樣本:
- 在你的
buildSrc專案中
構建.gradle
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
implementation "io.swagger:swagger-core:1.6.2"
}
您的自定義ModelConverter類在src/main/java,例如com.sample.MyCustomConverter
- 在您的根
build.gradle腳本中:
您可以參考您的MyCustomConverter類,它已經在腳本類路徑中可用,無需classpath在buildscript
swagger {
apiSource {
modelConverters = [ 'com.sample.MyCustomConverter' ]
// ....
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/530127.html
上一篇:由于發布了ReactNative版本0.71.0-rc.0,ReactNativeAndroid構建失敗并出現不同的錯誤,過去幾天代碼沒有任何更改
下一篇:執行com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction時發生故障
