java - 找不到参数的方法 jaxws() [com.sun.xml.ws:jaxws-tools:2.1.4]
问题描述
我正在尝试使用以下代码生成 java 类,但由于某些gradle
插件问题而失败。
我搜索了它,发现有很多插件可用于生成 java 类,xsd
但只有少数插件可用于生成plugins
代码表单wsdl
。
jaxb
是我想使用的其中之一。
这是我的 build.gradle 文件:
configurations {
jaxws
}
buildscript {
ext {
springBootVersion = "2.1.4.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-web-services'
compile 'org.apache.httpcomponents:httpclient'
compile 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
task wsimport {
ext.destDir = file("${projectDir}/src/main/generated")
doLast {
ant {
sourceSets.main.output.classesDir.mkdirs()
destDir.mkdirs()
taskdef(name: 'wsimport',
classname: 'com.sun.tools.ws.ant.WsImport',
classpath: configurations.jaxws.asPath
)
wsimport(keep: true,
destdir: sourceSets.main.output.classesDir,
sourcedestdir: destDir,
extension: "true",
verbose: "false",
quiet: "false",
package: "com.abc.test",
xnocompile: "true",
wsdl: '${projectDir}/src/main/resources/wsdls/wsdl_1.0.0.wsdl') {
xjcarg(value: "-XautoNameResolution")
}
}
}
}
compileJava {
dependsOn wsimport
source wsimport.destDir
}
bootJar {
baseName = 'API'
version = '1.0'
}
现在这是我尝试使用命令行构建项目时遇到的错误。
C:\DEV\workspace\API>gradlew clean build --stacktrace
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\DEV\workspace\API\build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'API'.
> Could not find method jaxws() for arguments [com.sun.xml.ws:jaxws-tools:2.1.4] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
解决方案
configurations {
jaxws
}
buildscript {
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
}
该配置jaxws
不适用于构建脚本依赖项。首先,它被放置在buildscript
配置之外,因此不可见。其次,构建脚本依赖只允许classpath
配置(构建脚本的外部依赖)。jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
从构建脚本依赖项中删除修复问题
找不到参数的方法 jaxws() [...]
下一个问题是您将 jax-ws 依赖项定义为
compile 'com.sun.xml.ws:jaxws-tools:2.1.4'
并尝试将其引用为
taskdef(name: 'wsimport',
classname: 'com.sun.tools.ws.ant.WsImport',
classpath: configurations.jaxws.asPath)
^^^^^
jaxws
到目前为止,配置没有定义依赖项,因此路径为空。将相关依赖项更改为
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
很可能会为您解决此问题。
更新
由于 Gradle 替换File classesDir
为FileCollection classesDirs
,根据您的评论,您现在收到错误
方法没有签名:org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection.mkdirs() 适用于参数类型:() 值:[] 可能的解决方案:min()、tails()、first()、inits (), 减号(org.gradle.api.file.FileCollection), min(java.util.Comparator)
在线的
sourceSets.main.output.classesDirs.mkdirs()
如果您只有 1 个类输出目录,解决方法是使用
sourceSets.main.output.classesDirs.singleFile.mkdirs()
推荐阅读
- maxima - 方程未完全求解
- html - 当我使用 github 发布我的网站时,没有显示背景视频
- excel - 填充列中的可见单元格
- angular - 如何在 Angular 上上传图像,以便每次有人通过应用程序上传图像时图像将存储在我的 assets/img 文件夹中?
- javascript - Solana 检查钱包的所有 spl 代币余额
- python - 使用 Django 时出现“TypeError:无法解压不可迭代的 AsyncResult 对象”?
- visual-studio-code - 如何在 Visual Studio Code 中设置自定义代码?
- web - PWA 只能在桌面版 Chrome 中运行?
- javascript - reactjs问题中的验证检查
- javascript - 询问AES加密实践