Generate Java code from multiple wsdls using gradle

I am migrating from maven to gradle. I started with gradle in it which generated couple of gradle files with a lot of dependencies into build.gradle. However, I did not get any entry of the wsdls to generate java code using wsdl2code plugin. Any suggestions?pom.xml (16.4 KB)

You could use the ant task and Gradle’s ant integration

eg

apply plugin: java
ext {
    wsdlDir = 'src/main/wsdl'
}
configurations {
    axis
}
dependencies {
    axis 'org.apache.axis2:axis2-ant-plugin:1.7.8'
}
task generateCode {
   inputs.dir wsdlDir
   outputs.dir "$buildDir/codegen"
   doLast {
      ant.taskdef(
         name: 'codegen', 
         classname: 'org.apache.axis2.tool.ant.AntCodegenTask', 
         classpath: configurations.axis.asPath 
      )
      ant.codegen(
         wsdlfilename:"$wsdlDir/OfferCodeService-v5.wsdl",
         output: "$buildDir/codegen"
      )
      ant.codegen(    
         wsdlfilename:"$wsdlDir/ProductOfferingService_v11.wsdl",
         output: "$buildDir/codegen",
         syncOnly: 'true'
      )
      // etc
   }
}
compileJava.dependsOn generateCode
sourceSets.main.java.srcDir "$buildDir/codegen"

Still getting compilation errors, unable to figure out… There is nothing in my gradle above which is executing at runtime except junit. Can you please suggest.

buildscript {
repositories { mavenCentral() }
// dependencies { classpath(“org.springframework.boot:spring-boot-gradle-plugin:1.1.7.RELEASE”) }
}

apply plugin: ‘java’
apply plugin: ‘maven’
apply plugin: ‘application’
apply plugin: ‘intellij’

//defaultTasks ‘clean’, ‘build’

group = ‘com.guftgupoint.data’
version = ‘8.7.1.30-SNAPSHOT’

description = “Guftgu-Trunk”

//default wsdl directory path
def wsdlDir = file(new File(‘src/main/wsdl’))
def buildDir = file(new File(‘target/generated-sources/axis2’))

task wrapper(type: Wrapper) {
gradleVersion = ‘2.13’
}

sourceCompatibility = 1.7
targetCompatibility = 1.7

jar { baseName = ‘guftgu’ }

configurations {
compile
runtime
axisGenAntTask
}

repositories {

maven { url "http://it-maven.guftgupoint.com/content/repositories/m2repo-snapshots" }
maven { url "http://it-maven/content/groups/m2repo/" }
maven { url "http://repo.maven.apache.org/maven2" }

}
dependencies {
compile group: ‘org.springframework’, name: ‘spring-context’, version:‘3.1.1.RELEASE’
compile group: ‘org.springframework’, name: ‘spring-context-support’, version:‘3.1.1.RELEASE’
compile(group: ‘org.springframework’, name: ‘spring-core’, version:‘3.1.1.RELEASE’)
{
exclude(module: ‘commons-logging’)
}
compile group: ‘org.springframework’, name: ‘spring-jdbc’, version:‘3.1.1.RELEASE’
compile group: ‘org.springframework’, name: ‘spring-orm’, version:‘3.1.1.RELEASE’
compile group: ‘com.ibatis’, name: ‘ibatis’, version:‘2.3.0’
compile group: ‘commons-lang’, name: ‘commons-lang’, version:‘2.4’
compile group: ‘commons-collections’, name: ‘commons-collections’, version:‘3.2.2’
compile group: ‘commons-logging’, name: ‘commons-logging’, version:‘1.2’
compile(group: ‘com.ami.sed’, name: ‘keyvalueutil’, version:‘1.7’)
{
exclude(module: ‘commons-lang’)
exclude(module: ‘slf4j-api’)
}
compile group: ‘aspectj’, name: ‘aspectjweaver’, version:‘1.5.3’
compile group: ‘org.apache.axis2’, name: ‘axis2’, version:‘1.7.3’
compile(group: ‘org.apache.axis2’, name: ‘axis2-codegen’, version:‘1.7.3’)
{
exclude(module: ‘commons-logging’)
}
compile(group: ‘org.apache.ws.commons.axiom’, name: ‘axiom-impl’, version:‘1.2.19’)
{
exclude(module: ‘geronimo-javamail_1.4_spec’)
exclude(module: ‘geronimo-activation_1.1_spec’)
}
compile group: ‘xml-apis’, name: ‘xml-apis’, version:‘1.3.04’
compile(group: ‘com.dish.dishlayer’, name: ‘dishlayerChecksumUtility’, version:‘1.2’)
{
exclude(module: ‘spring’)
exclude(module: ‘commons-collections’)
exclude(module: ‘commons-logging’)
}
compile(group: ‘org.apache.axis2’, name: ‘axis2-kernel’, version:‘1.7.3’)
{
exclude(module: ‘commons-logging’)
exclude(module: ‘commons-codec’)
exclude(module: ‘wstx-asl’)
exclude(module: ‘commons-io’)
}
compile group: ‘javax.activation’, name: ‘activation’, version:‘1.1’
compile group: ‘backport-util-concurrent’, name: ‘backport-util-concurrent’, version:‘3.1’
compile group: ‘commons-codec’, name: ‘commons-codec’, version:‘1.3’
compile(group: ‘commons-configuration’, name: ‘commons-configuration’, version:‘1.6’)
{
exclude(module: ‘commons-logging’)
exclude(module: ‘commons-collections’)
}
compile(group: ‘net.sf.ehcache’, name: ‘ehcache-core’, version:‘2.6.2’)
{
exclude(module: ‘slf4j-api’)

}
compile(group: 'org.apache.axis2', name: 'axis2-fastinfoset', version:'1.7.3') 
{
	exclude(module: 'commons-logging')
	exclude(module: 'httpcore')
	exclude(module: 'commons-codec')
}
compile group: 'quartz', name: 'quartz', version:'1.6.6'
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.6.4'
runtime group: 'log4j', name: 'log4j', version:'1.2.16'
testCompile group: 'junit', name: 'junit', version:'4.8.1'
testCompile group: 'commons-dbcp', name: 'commons-dbcp', version:'1.4'
testCompile group: 'oracle', name: 'classes12', version:'9.1'
testCompile group: 'javax.transaction', name: 'jta', version:'1.0.1B'
compile(group: 'weblogic', name: 'weblogic', version:'8.1.4.0')
//	compile(group: 'org.apache.axis2', name: 'axis2-wsdl2code-maven-plugin', version: '1.6.2'){
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
 This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
 Please review and delete this closure when resolved. */
axisGenAntTask 'org.apache.axis2:axis2-ant-plugin:1.7.8'

}

task generateCode {
// inputs.dir wsdlDir
// outputs.dir “$buildDir/codegen”
doLast {
ant.taskdef(
name: ‘codegen’,
classname: ‘org.apache.axis2.tool.ant.AntCodegenTask’,
classpath: configurations.axisGenAntTask.asPath
)
ant.codegen(
wsdlfilename:"$wsdlDir/OfferCodeService-v5.wsdl",
output: “$buildDir/codegen”
)
ant.codegen(
wsdlfilename:"$wsdlDir/ProductOfferingService_v11.wsdl",
output: “$buildDir/codegen”,
syncOnly: ‘true’
)
ant.codegen(
wsdlfilename:"$wsdlDir/ProgrammingService-v11.wsdl",
output: “$buildDir/codegen”
)
}
}

  1. You haven’t included the error so I can’t help
  2. Don’t create a variable named buildDir as it will be confused/conflict with project.buildDir
  3. Don’t generate code under target directory, generate under build directory (project.buildDir) so it gets cleaned by the clean task
  4. Better to define wsdlDir in the ext { ... } block as in my example

Thanks for the suggession, the error is mentioned below, it seems the xsds are not compiled due to which it is showing the objects not found OR stub not generated.

D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:12: error: package com.aminetwork.www.xsd.productchannellineuptype._2009_09_20 does not exist
import com.aminetwork.www.xsd.productchannellineuptype._2009_09_20.ProductChannelLineupType;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:13: error: package com.aminetwork.www.xsd.productstationservicedata._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicedata._2010_12_01.ProductAndChannel;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:14: error: package com.aminetwork.www.xsd.productstationservicedata._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicedata._2010_12_01.RsNetDataType;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:15: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationByProductIdRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:16: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationByProductIdResponse;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:17: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationChannelLineupRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:18: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationChannelLineupResponse;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:19: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:20: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProductStationResponse;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:21: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProgrammingProductByChannelRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:22: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveProgrammingProductByChannelResponse;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:23: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveRsNetRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:24: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveRsNetResponse;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:25: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveSpotBeamsRequest;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:26: error: package com.aminetwork.www.xsd.productstationservicemessage._2010_12_01 does not exist
import com.aminetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveSpotBeamsResponse;

D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:27: error: package com.aminetwork.www.xsd.programmingproduct._2009_09_20 does not exist
import com.aminetwork.www.xsd.programmingproduct._2009_09_20.ProgrammingProduct;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:28: error: package com.guftgupoint.axis2 does not exist
import com.guftgupoint.axis2.ProductStationServiceFaultMsg;
^
D:\java_projects\US67132\src\main\java\com\guftgupoint\data\dataservice\ProductStationDataService.java:29: error: package com.guftgupoint.axis2 does not exist
import com.guftgupoint.axis2.ProductStationService_v3_0Stub;
^
Note: D:\java_projects\US67132\src\main\java\com\guftgupoint\data\impl\cache\EhCacheImpl.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I think you missed these bits

compileJava.dependsOn generateCode
sourceSets.main.java.srcDir "$buildDir/codegen" 

Same issue even after adding the last two lines.
This is where I have added them in build.gradle


ant.codegen(
wsdlfilename:“$wsdlDir/DishNetWirelineService.wsdl”,
output: “$buildDir/codegen”
)
ant.codegen(
wsdlfilename:“$wsdlDir/PreBuiltCommitmentService-v1.wsdl”,
output: “$buildDir/codegen”
)
compileJava.dependsOn generateCode
sourceSets.main.java.srcDir “$buildDir/codegen”
}
}


I think the xsds are not getting converted to corresponding java classes. Is it because of the package name missing in the pom (which had below entry)


			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
			<version>1.6.2</version>
			<configuration>
				<outputDirectory>target/generated-sources/axis2</outputDirectory>
				<packageName>com.echostar.axis2</packageName>
				<unpackClasses>true</unpackClasses>
				<options>
					<property>
						<name>osv</name>
						<value>osv</value>
					</property>
				</options>
			</configuration>
			<executions>
				<execution>
					<id>OfferCodeService</id>
					<goals>
						<goal>wsdl2code</goal>
					</goals>
					<configuration>
						<wsdlFile>${wsdl.dir}OfferCodeService-v5.wsdl</wsdlFile>
					</configuration>
				</execution>

Latest Error

1 does not exist
import com.dishnetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveSpotBeamsRequest;
^
D:\java_projects\US67132\src\main\java\com\echostar\data\dataservice\ProductStationDataService.java:26: error: package com.dishnetwork.www.xsd.productstationservicemessage._2010_12_0
1 does not exist
import com.dishnetwork.www.xsd.productstationservicemessage._2010_12_01.RetrieveSpotBeamsResponse;
^
D:\java_projects\US67132\src\main\java\com\echostar\data\dataservice\ProductStationDataService.java:27: error: package com.dishnetwork.www.xsd.programmingproduct._2009_09_20 does not
exist
import com.dishnetwork.www.xsd.programmingproduct._2009_09_20.ProgrammingProduct;
^
D:\java_projects\US67132\src\main\java\com\echostar\data\dataservice\ProductStationDataService.java:28: error: package com.echostar.axis2 does not exist
import com.echostar.axis2.ProductStationServiceFaultMsg;
^
D:\java_projects\US67132\src\main\java\com\echostar\data\dataservice\ProductStationDataService.java:29: error: package com.echostar.axis2 does not exist
import com.echostar.axis2.ProductStationService_v3_0Stub;
^
Note: D:\java_projects\US67132\src\main\java\com\echostar\data\impl\cache\EhCacheImpl.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 17.189 secs

No, put the lines at the top level, outside the task definition, as in my example

It is same error :frowning:
ant.codegen(
wsdlfilename:"$wsdlDir/PreBuiltCommitmentService-v1.wsdl",
output: “$buildDir/codegen”
)
}
}
compileJava.dependsOn generateCode
sourceSets.main.java.srcDir “$buildDir/codegen”

What happens when you run

gradle generateCode

Are the java files under build/codegen?

Yes they are getting generated at the location you’ve mentioned. In fact the issue seems to me is java files corresponding to xsd is not getting generated.

Ok, I’m guessing that’s another maven plugin that needs to be migrated to gradle?

Also, I noted that you commented this out

inputs.dir wsdlDir
outputs.dir "$buildDir/codegen"

If you put this back you can benefit from faster builds when the wsdls have not changed

I have uncommented them already, but sent you old one

Ok, so looks like your wsdl code gen issue is now resolved. Now you have a similar xsd issue (guessing there’s an ant task for that too)

Yes, How about adding below code in every ant.codegen block
ant.codegen(
wsdlfilename:"$wsdlDir/TechstoreDataService.wsdl",
databindingName: ‘adb’,
allPorts: ‘true’,
overWrite: ‘true’,
output: “$buildDir/codegen”,
unpackClasses: ‘true’
)
ant.codegen(
wsdlfilename:"$wsdlDir/DishNetWirelineService.wsdl",
databindingName: ‘adb’,
allPorts: ‘true’,
overWrite: ‘true’,
output: “$buildDir/codegen”,
unpackClasses: ‘true’
)
ant.codegen(
wsdlfilename:"$wsdlDir/PreBuiltCommitmentService-v1.wsdl",
databindingName: ‘adb’,
allPorts: ‘true’,
overWrite: ‘true’,
output: “$buildDir/codegen”,
unpackClasses: ‘true’
)
}
}
compileJava.dependsOn generateCode
sourceSets.main.java.srcDir “$buildDir/codegen”

After making the above changes I am getting xsd corresponding code generated, but now getting below mentioned error:

Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/Image/2009_09_20}Image’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/DiscountCode/2009_09_20}DiscountCode’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/AcquisitionChannel/2009_09_20}AcquisitionChannel’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/TargetMarket/2011_10_14}TargetMarket’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/GeographicalLocation/2009_09_20}GeographicalLocation’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/Image/2009_09_20}Image’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/DPAttributes/2009_09_20}DPAttributes’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/DiscountCode/2009_09_20}DiscountCode’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/BillingOffer/2009_09_20}BillingOffer’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/AbstractProduct/2009_09_20}AbstractProduct’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/EPG/2009_09_20}EPG’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/Station/2009_09_20}Station’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/OrbitalLocation/2009_09_20}OrbitalLocation’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/Beam/2009_09_20}Beam’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/ChannelLineup/2009_09_20}ChannelLineup’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/GeographicalLocation/2009_09_20}GeographicalLocation’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/Image/2009_09_20}Image’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/DPAttributes/2009_09_20}DPAttributes’
Could not find any schema type associated with the Element ‘{http://www.aminetwork.com/xsd/DiscountCode/2009_09_20}DiscountCode’

Note: you can use a list to reduce the code. Eg:

['a.wsdl', 'b.wsdl', 'c.wsdl'].each { wsdl ->
   ant.codegen(
      wsdlfilename:"$wsdlDir/$wsdl",
      databindingName: ‘adb’,
      // etc
   ) 
}

Thanks Lance, but what about the build failure, although I am getting the java code corresponding to xsd getting generated. Any thoughts OR shall I move to wsd2java plugin.

I’m not familiar with axis codegen and was just trying to get you started. You’ll have to do your own investigation from here.

Perhaps you’ve got another plugin in your maven build which generates java from xsd? In which case you’ll need to do the same in the Gradle build.

Or perhaps the Maven codegen plugin sets some defaults which aren’t set by default when using the ant task? A poke through the codegen Maven plugin code might help

Thank you
Is this what you said, how about syncOnly : ‘true’ only for second wsdl??

task generateCode {
inputs.dir wsdlDir
outputs.dir “$buildDir/codegen”
doLast {
ant.taskdef(
name: ‘codegen’,
classname: ‘org.apache.axis2.tool.ant.AntCodegenTask’,
classpath: configurations.axisGenAntTask.asPath
)
[‘OfferCodeService-v5.wsdl’, ‘ProductOfferingService_v11.wsdl’, ‘ProgrammingService-v11.wsdl’, ‘billingMapperService-v13.wsdl’, ‘RetrieveLocationService-v2.wsdl’, ‘RetrieveEquipmentsService-v3.wsdl’, ‘ProductStationService-v3.wsdl’, ‘PricerService-v1.wsdl’, ‘NetqualService-v3.wsdl’, ‘EquipmentsInfoService.wsdl’, ‘DistributeRulesService.wsdl’, ‘distributeEPCProjectWS.wsdl’, ‘ServiceCodeCategoryLookupService-v3.wsdl’, ‘AppPropertyKeyValueService.wsdl’, ‘TechstoreDataService.wsdl’, ‘DishNetWirelineService.wsdl’, ‘PreBuiltCommitmentService-v1.wsdl’].each { wsdl ->
ant.codegen(
“$wsdlDir/$wsdl”,
databindingName: ‘adb’,
allPorts: ‘true’,
overWrite: ‘true’,
output: ‘$buildDir/codegen’,
unpackClasses: ‘true’
)
}
}
}
compileJava.dependsOn generateCode
sourceSets.main.java.srcDir “$buildDir/codegen”