How to pass trustStore property in gradle build script

yogsma :

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.

Opal :

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')

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=475042&siteId=1