我正在尝试通过 gradle 脚本为 SOAP 网络服务生成类。我正在使用 Maven Central 中可用的插件 gradle-jaxws-plugin
。
我的脚本如下所示:
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
,但这也不起作用。有没有一种干净的方法来传递这些属性?我也想知道当我有一个自动构建时我将如何在生产中处理这个问题。
最佳答案
通常,由于这些数据是敏感的,它们应该通过命令行传递,或者 - 如果您在生产中有自动构建 - 应该通过例如在系统中配置环境变量(这是最常处理的方式)。
您可以通过 gradle.properties
配置系统属性,但它们 should be prepend带有 systemProp
前缀,所以:
gradle.properties:
systemProp.javax.net.ssl.trustStore=cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
此外,apply
部分下的 build.gradle
中的以下代码也应该可以正常工作:
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')
关于java - 如何在 gradle 构建脚本中传递 trustStore 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43483514/