简体   繁体   English

Gradle,rt.jar访问限制

[英]Gradle, rt.jar access restriction

I am using a Gradle build that contains among other things: 我正在使用Gradle构建,其中包含:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'

repositories {
  flatDir { dirs "${System.env.JAVA_HOME}/jre/lib" }
}

dependencies {
  compile name: 'rt' 
}

It builds, that's great, yet the eclipse plugin is giving me a hard time on the rt.jar classes: 它构建,这很棒,但是eclipse插件让我在rt.jar类上遇到困难:

Access restriction: The type XMLSerializer is not accessible due to restriction on required library /usr/local/apps/jdk1.8.0_11/jre/lib/rt.jar 访问限制:由于对所需库的限制,无法访问XMLSerializer类型/usr/local/apps/jdk1.8.0_11/jre/lib/rt.jar

Which I understand. 我明白了

Now I know you will tell me to just not use those classes. 现在我知道你会告诉我不要使用那些课程。 But you know how it is, I'm working on an ancient project and I just need to make it work for now. 但你知道它是怎么回事,我正在研究一个古老的项目,我现在只需要让它工作。

My first question is: where is that restriction info located at? 我的第一个问题是:限制信息位于何处?

And obviously: How can I get around that? 显然:我怎么能绕过那个? I'm thinking of uploading it as a artifact on my Nexus repo, anything easier than that? 我想把它作为我的Nexus仓库上的工件上传,比这更容易吗?

Explanation: There is an eclipse plugin in gradle that allows for modifying the behavior for generating eclipse configs from the gradle model. 说明: gradle中有一个eclipse插件,允许修改从gradle模型生成eclipse配置的行为。 This plugin has one sub-set-feature called classpath allowing to modify the generated .classpath file of eclipse. 这个插件有一个名为classpath子集特性,允许修改生成的.classpath文件。

Code: 码:

import org.gradle.plugins.ide.eclipse.model.AccessRule

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
                jre.accessRules.add(new AccessRule('0', 'com/**'))
                jre.accessRules.add(new AccessRule('0', 'sun/**'))
            }
        }
    }
}

From: https://discuss.gradle.org/t/buildship-1-0-18-is-now-available/19012 (section "Access Rules") 来自: https //discuss.gradle.org/t/buildship-1-0-18-is-now-available/19012 (“访问规则”部分)

Parameters explained: 参数说明:

  • '0' = accessible '0' =无法访问
  • '1' = nonaccessible '1' =无法访问
  • '2' = discouraged '2' =气馁

My personal usage looks like this: 我的个人用法如下:

eclipse.classpath {
    file.whenMerged {
        entries.each { source -> 
            if (source.kind == 'con' && source.path.startsWith('org.eclipse.jdt.launching.JRE_CONTAINER')) {
                source.accessRules.add(new AccessRule('0', 'sun/applet/AppletAudioClip'))
                source.accessRules.add(new AccessRule('0', 'javax/swing/**'))
                source.accessRules.add(new AccessRule('0', 'com/sun/java/swing/**'))
                source.accessRules.add(new AccessRule('0', 'javafx/**'))
                source.accessRules.add(new AccessRule('0', 'sun/net/www/protocol/**'))
            }
        }
    }
}

And the output is this: 输出是这样的:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/">
    <accessrules>
        <accessrule kind="accessible" pattern="sun/applet/AppletAudioClip"/>
        <accessrule kind="accessible" pattern="javax/swing/**"/>
        <accessrule kind="accessible" pattern="com/sun/java/swing/**"/>
        <accessrule kind="accessible" pattern="javafx/**"/>
        <accessrule kind="accessible" pattern="sun/net/www/protocol/**"/>
    </accessrules>
</classpathentry>

Tested & worked with: 经过测试和使用:

  • Eclipse Version: Oxygen Release Candidate 3 (4.7.0 RC3) Eclipse版本:氧气释放候选3(4.7.0 RC3)
  • Gradle Version: Gradle 3.5.1 Gradle版本:Gradle 3.5.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM