如何超越gradle wsimport任务JDK 8访问限制?

时间:2014-02-26 14:28:38

标签: gradle java-8 wsimport

我的gradle构建中有一个wsimport任务正常工作,直到Java 7:

task wsimport {
    ext.destDir = file("${buildDir}/generated/java")
    ext.wsdlSrc = file("src/main/resources/schema/example/my.wsdl")
    ext.bindingSrc = file("src/main/resources/schema/example/bindings.xsd")
    outputs.dir destDir
    doLast {
        ant {
            destDir.mkdirs()
            taskdef(name: 'wsimport',
                classname: 'com.sun.tools.ws.ant.WsImport',
                classpath: configurations.jaxws.asPath)
            wsimport(keep: true,
                package: 'net.example.my',
                xnocompile: true,
                quiet: true,
                sourcedestdir: destDir,
                wsdl: wsdlSrc,
                binding: bindingSrc,
                encoding: "UTF-8"
            )
        }
    }
}

切换到JDK 8(build 1.8.0-b129)时出现以下错误:

java.lang.AssertionError: org.xml.sax.SAXParseException; systemId: ... schema_reference:
Failed to read schema document 'xjc.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property.

搜索问题我发现了以下帖子(令人惊讶地描述了Java 7的问题):https://github.com/stianh/gradle-jaxb-plugin/issues/20 但我无法将环境/参数传递给wsimport / xjc。

如何禁用此访问权限或限制?

1 个答案:

答案 0 :(得分:5)

我找到的唯一可行解决方案是使用反射设置系统属性:

task wsimport {
  System.setProperty('javax.xml.accessExternalSchema', 'file')
  ...
}

使用extsystemProperty的所有其他解决方案对我无效。 我安装了gradle 1.11。