I am trying to generate classes for a SOAP webservice through a gradle script. I am using a plugin gradle-jaxws-plugin
which is available in maven central.
My script looks like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "eu.schnuckelig.gradle:gradle-jaxws-plugin:1.0.2"
}
}
apply plugin: 'maven'
apply plugin: 'jaxws'
jaxws {
System.setProperty('javax.xml.accessExternalSchema', 'all')
packageName = 'com.myservice'
wsdlURL = 'https://example.org/services/users.svc?wsdl'
}
repositories {
mavenCentral()
}
If I use this script as it is, I get following error
[ant:wsimport] [ERROR] sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
One way of resolving this error, I tried is gradle build -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit
. This worked. But I want to pass these jvm properties in build script.
I tried systemProperty.set()
, but it didn't work. I am trying with gradle.properties
, but that doesn't work either. Is there a clean way to pass these properties? Also I am wondering how I will handle this in production when I will have an automated build.
System propertiesUsing the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle.
The global properties file should be located in your home directory: On Windows: C:\Users\<you>\. gradle\gradle. properties.
Click on Environment variables. After that, click the New option. Now, create user variable, enter the variable name as Gradle_Home and paste the value of the home path e.g., C:\gradle-6.0. 1 in the variable value field.
On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.
Typically, since such data are sensitive they should be passed via command line or - if you have an automated build in production - should be configured in system via e.g. environment variables (this is how it's handled most often).
You can configure system properties via gradle.properties
but they should be prepend with systemProp
prefix, so:
gradle.properties:
systemProp.javax.net.ssl.trustStore=cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
Also the following piece of code put in build.gradle
just under apply
section should work as well:
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "eu.schnuckelig.gradle:gradle-jaxws-plugin:1.0.2"
}
}
apply plugin: 'maven'
apply plugin: 'jaxws'
System.setProperty('javax.net.ssl.trustStore', 'cacerts')
System.setProperty('javax.net.ssl.trustStorePassword', 'changeit')
This should work
configurations {
jaxws
}
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
task wsimport {
ext.destDir = file("${projectDir}/src/main/generated")
System.setProperty('javax.net.ssl.keyStoreType', 'pkcs12')
System.setProperty('javax.net.ssl.keyStore', 'client.pfx')
System.setProperty('javax.net.ssl.keyStorePassword', 'xxxxxxxxx')
System.setProperty('javax.net.ssl.keyPassword', 'xxxxxxxxx')
System.setProperty('javax.net.ssl.trustStore', 'truststore.jks')
System.setProperty('javax.net.ssl.trustStorePassword', 'xxxxxxxx')
System.setProperty('sun.security.ssl.allowUnsafeRenegotiation','true')
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.example.client.api",
xnocompile: "true",
wsdl: 'https://test.com/test.asmx?wsdl') {
xjcarg(value: "-XautoNameResolution")
}
}
}
}
compileJava {
dependsOn wsimport
source wsimport.destDir
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With