我在ANT build.xml中有以下代码,它将WSDL转换为Java。它使用axis-ant.jar 1.4.0
<!-- Build generated jars -->
<target name="axis-WSDL-2-Java" depends="init">
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
<axis-wsdl2java
output="${build.gen.src}"
testcase="true"
verbose="true"
url="${build.src.wsdl.v1}/${build.ws.wsdlfile}" >
</axis-wsdl2java>
<!-- Compile artifacts -->
<echo message="Compiling WS artifact source for Axis..." />
<javac destdir="${build.gen.classes}" debug="true" >
<src path="${build.gen.src}" />
<classpath>
<pathelement path="${build.lib.3rdParty}" />
<path refid="axis.classpath" />
</classpath>
</javac>
<jar .... some jar code here...
</jar>
</target>
现在,我将构建脚本转换为Gradle,并产生了以下Gradle代码snap.
//wsdl to java
task axisWSDLTojava() << {
println "-- Inside axisWSDLToJava"
def flGen = new File( "$project.buildDir/thidsGen/src" )
flGen.mkdirs()
flGen = new File( "$project.buildDir/thidsGen/classes" )
flGen.mkdirs()
ant {
taskdef(
resource: 'axis-tasks.properties',
classpath: configurations.axisAnt.asPath )
axis-wsdl2java(
output: "$project.buildDir/thidsGen/src",
testcase: "true",
verbose: "true",
url: "$projectDir/src/ws/v1/wsdl/MDSSFileInfo.wsdl")
}
}
//compile generated src to classes
task compileJavaWsArtifacts (type: JavaCompile, dependsOn: axisWSDLTojava) << {
println "-- Inside compileGenSrc"
source = "$project.buildDir/thidsGen/src"
classpath = configurations.axisAnt.asPath
destinationDir = "$project.buildDir/thidsGen/classes"
}
// Build jar with web service artifacts
task jarWsArtifacts( type: Jar, dependsOn: compileJavaWsArtifacts ) << {
println "-- Inside jarWsArtifacts"
// some code here
// some code here to create the jar etc
}
调用相应任务的Gradle逻辑都设置好了,即我在CompileJava Gradle task中调用上述任务为dependsOn .
// Compile java server components - must have artifacts first
compileJava {
dependsOn jarWsArtifacts
}
Gradle中的Configuration部分定义为:
// Custom configurations
configurations {
axisAnt
}
Gradle中的Dependencies部分定义为:
// Define dependencies
dependencies {
// Compilation
//compile 'groupid:artifactid:x.x.x'
//compile 'groupid:artifactid:x.x.x@yyy'
//other bunch of dependencies... come here which are required for compile task in Gradle
//axis-wsdl2java generates java files, which generates class files and jard into a -ws.jar file
compile fileTree( dir: 'build/resultantJar', include: "$ProjectName-ws-*.jar" )
// Unit Tests
testCompile 'xxx:yyy:x.x.x'
testCompile 'xxx:yyy:x.x.x'
//more artifacts for testCompile..
// Integration tests
// Everything from compile and testCompile targets
integrationTestCompile configurations.compile
integrationTestCompile configurations.testCompile
// Output of compiling "main" files
integrationTestCompile sourceSets.main.output
// Additional dependencies from war and others
integrationTestCompile 'xxx:yyy:x.x.x'
integrationTestCompile 'xxx:yyy:x.x.x'
//other enteries for IT test task
// All configuration files in conf folder in source control required for IT tests.
integrationTestRuntime files( 'conf' )
//Axis-ANT
axisAnt 'axis:axis-ant:1.4.0'
axisAnt 'othergroupid:otherartifactid:x.x.x'
axisAnt 'othergroupid:otherartifactid:x.x.x'
// comes here which are required for axis-wsdl2java to work
}
BUT,当运行"gradle clean build"时,我得到以下错误信息:
:axisWSDLTojava FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/production/jenkinsAKS/workspace/DFDailyFeedSvc/build.gradle' line: 90
* What went wrong:
Execution failed for task ':axisWSDLTojava'.
> No such property: axis for class: org.gradle.api.internal.project.DefaultAntBuilder
Possible solutions: ant
知道为什么它不能看到axis-wsdl2java(我看到它定义在axis-tasks中)吗?axis-ant.jar 1.4.0版本中的properties文件如下:)
#properties file for taskdefing the public Axis taskdefs
axis-wsdl2java=org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask
axis-java2wsdl=org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask
axis-admin=org.apache.axis.tools.ant.axis.AdminClientTask
OK, resolved.
在Gradle代码中更改以下内容就可以达到目的。不知道为什么Gradle没有选择没有双引号的方式。原因:在Java/Groovy (Gradle使用Groovy)中,你不能在函数名中有"-"(你可以有giga_fifa,但不能有giga-fifa)。很高兴,用"解决了。
axis-wsdl2java(
"axis-wsdl2java"(
另外,在我使用"$project "的地方。buildDir . .我将其更改为$buildDir,因为ANT抱怨项目。buildDir未找到或在$project中写入buildDir时未找到。buildDir格式。使用$buildDir解决了这些问题。
另外,compileJavaWsArtifacts没有看到生成的src文件!!尽管在Gradle构建中使用wsdl2java操作后成功生成了。于是,神子使用了以下代码:
//compile generated src to classes
//task compileJavaWsArtifacts (type: JavaCompile, dependsOn: axisWSDLToJava) << {
// source = "$buildDir/thidsGen/src"
// classpath = configurations.axisAnt.asPath
// destinationDir = "$buildDir/thidsGen/classes"
//}
//compile generated src to classes
task compileJavaWsArtifacts (dependsOn: axisWSDLToJava) << {
ant {
javac( destdir: "$buildDir/thidsGen/classes", debug: 'true', includeAntRuntime: 'no', classpath: configurations.axisAnt.asPath ) {
src( path: "$buildDir/thidsGen/src" )
}
}
}