How to pass trustStore property to gradle build script

I am trying to create classes for a SOAP web service through a gradle script. I am using a plugin gradle-jaxws-plugin

that is available at maven central.

My script looks like this:

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 is, I get the 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 to resolve this error, I tried - gradle build -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit

. It worked. But I want to pass these jvm properties to the build script.

I tried systemProperty.set()

it but it didn't work. I try with gradle.properties

but that doesn't work either. Is there a clean way to pass these properties? Also I'm wondering how I will go about doing this in production when I have an automatic build.

+3


source to share


2 answers


Typically, since such data is sensitive, it should be passed through the command line or - if you have an automated build in production - it should be configured on the system via, for example, environment variables (this is most often handled).

You can customize system properties with gradle.properties

, but they must be prefixed systemProp

, so:

gradle.properties



systemProp.javax.net.ssl.trustStore=cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit

      

Also the following piece of code, placed in build.gradle

just underneath apply

: build.gradle should work

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

      

+6


source


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
}

      

+1


source







All Articles