8

我正在尝试通过 gradle 脚本为 SOAP Web 服务生成类。我正在使用gradle-jaxws-pluginmaven Central 中提供的插件。

我的脚本如下所示:

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()
}

如果我按原样使用此脚本,则会出现以下错误

[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

我尝试过解决此错误的一种方法是gradle build -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit. 这行得通。但我想在构建脚本中传递这些 jvm 属性。

我试过systemProperty.set()了,但没有用。我正在尝试gradle.properties,但这也不起作用。有没有一种干净的方法来传递这些属性?另外我想知道当我将有一个自动构建时,我将如何在生产中处理这个问题。

4

2 回答 2

21

通常,由于此类数据很敏感,因此它们应该通过命令行传递,或者 - 如果您在生产环境中有自动构建 - 应该通过例如环境变量在系统中进行配置(这是最常见的处理方式)。

您可以通过配置系统属性,gradle.properties但它们应该带有systemProp前缀,因此:

gradle.properties

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

此外,下面的部分代码也build.gradle应该apply可以工作: 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')
于 2017-04-19T04:54:00.303 回答
1

这应该工作

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
}
于 2017-04-19T15:06:44.370 回答