How to pass trustStore property in gradle build script

不羁的心 提交于 2019-12-03 16:43:31

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
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!