如何在Gradle构建脚本中传递trustStore属性 [英] How to pass trustStore property in gradle build script

查看:214
本文介绍了如何在Gradle构建脚本中传递trustStore属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过gradle脚本为SOAP Web服务生成类.我正在使用Maven Central中可用的插件gradle-jaxws-plugin.

I am trying to generate classes for a SOAP webservice through a gradle script. I am using a plugin gradle-jaxws-plugin which is available in maven 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()
}

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

If I use this script as it is, I get 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

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

One way of resolving this error, I tried is gradle build -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit. This worked. But I want to pass these jvm properties in build script.

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

I tried systemProperty.set(), but it didn't work. I am trying with gradle.properties, but that doesn't work either. Is there a clean way to pass these properties? Also I am wondering how I will handle this in production when I will have an automated build.

推荐答案

通常,由于此类数据很敏感,因此应通过命令行传递这些数据,或者-如果您具有自动生成的版本,则应通过例如在系统中进行配置.环境变量(这是最常使用的方式).

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

您可以通过gradle.properties配置系统属性,但应预先添加 systemProp前缀,所以:

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

同样,在apply部分下面的build.gradle中放置的以下代码也应正常工作: build.gradle

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

这篇关于如何在Gradle构建脚本中传递trustStore属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆