2017-04-18 145 views
2

我正在嘗試通過gradle腳本爲SOAP webservice生成類。我正在使用一個插件gradle-jaxws-plugin,它在maven central中可用。如何在gradle構建腳本中傳遞trustStore屬性

我的腳本看起來像下面:

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,但那也行不通。有沒有一種簡潔的方式來傳遞這些屬性?另外我想知道如何在生產中處理這個問題,當我有一個自動構建。

回答

5

通常,由於這些數據是敏感的,所以應該通過命令行傳遞,或者 - 如果您有生產中的自動構建 - 應該通過系統配置在系統中。環境變量(這是最經常處理的方式)。

您可以通過gradle.properties配置系統性能,但他們should be prependsystemProp前綴,所以:

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

的build.gradle選項,我已經試過之前,但它不工作。 – yogsma

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 
} 
相關問題