[英]Could not find method jaxws() for arguments [com.sun.xml.ws:jaxws-tools:2.1.4]
I am trying to generate java classes using following code but it's failing for some gradle
plugin issue. 我正在尝试使用以下代码生成Java类,但由于某些
gradle
插件问题而失败。
I searched for it and found there are many plugin available for generating the java classed from xsd
but only few plugins
for generating the code form wsdl
. 我搜索了它,发现有许多插件可用于生成从
xsd
分类的java,但只有少数plugins
用于生成代码形式wsdl
。 jaxb
is one of them which I thought to use. jaxb
是我想使用的其中之一。
Here is my build.gradle file: 这是我的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'
}
Now here is the error I am getting when I try to build project using command line. 现在这是我尝试使用命令行构建项目时遇到的错误。
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.
Taking reference from this code; 引用此代码; https://gist.github.com/ae6rt/8883335
https://gist.github.com/ae6rt/8883335
configurations {
jaxws
}
buildscript {
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
}
The configuration jaxws
is not applicable for build script dependencies. 配置
jaxws
不适用于构建脚本依赖项。 First, it is placed outside of the buildscript
configuration and thus not visible. 首先,它被放置在
buildscript
配置之外,因此不可见。 Second, build script dependencies allow for classpath
configuration only ( External dependencies for the build script ). 其次,构建脚本依赖项仅允许
classpath
配置( 构建脚本的外部依赖项 )。 Removing jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
from the build script dependencies fixes issue 从构建脚本依赖项中删除
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
修复了问题
Could not find method jaxws() for arguments [...]
找不到参数jaxws()的方法[...]
Next issue is that you define the jax-ws dependency as 下一个问题是您将jax-ws依赖项定义为
compile 'com.sun.xml.ws:jaxws-tools:2.1.4'
and try to reference it as 并尝试引用为
taskdef(name: 'wsimport',
classname: 'com.sun.tools.ws.ant.WsImport',
classpath: configurations.jaxws.asPath)
^^^^^
The jaxws
configuration has no dependencies defined so far, thus the path is empty. 到目前为止,
jaxws
配置尚未定义依赖项,因此路径为空。 Changing the dependency in question to 将相关依赖项更改为
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
is likely to resolve this issue for you. 可能会为您解决此问题。
Update 更新
Since Gradle replaced File classesDir
with FileCollection classesDirs
, as per your comment you're now receiving error 由于Gradle用
FileCollection classesDirs
替换了File classesDir
,根据您的评论,您现在收到错误
No signature of method: org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection.mkdirs() is applicable for argument types: () values: [] Possible solutions: min(), tails(), first(), inits(), minus(org.gradle.api.file.FileCollection), min(java.util.Comparator)
没有方法签名:org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection.mkdirs()适用于参数类型:()值:[]可能的解决方案:min(),tails(),first(),inits (),减号(org.gradle.api.file.FileCollection),减号(java.util.Comparator)
on line 在线
sourceSets.main.output.classesDirs.mkdirs()
If you've got only 1 classes output dir, a workaround would be to use 如果您只有1个类的输出目录,则可以使用一种解决方法
sourceSets.main.output.classesDirs.singleFile.mkdirs()
(from: FileCollection.getSingleFile() ) (来自: FileCollection.getSingleFile() )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.