简体   繁体   English

如何在 Gradle JAR 类路径构建脚本中包含 com.sun.tools JAR 并与我的 IDE 同步?

[英]How do I include com.sun.tools JAR in my Gradle JAR classpath buildscript and also sync with my IDE?

I need the com.sun.tools jar as a compile dependency, so I just copied it to my libs folder in my Intellij project.我需要 com.sun.tools jar 作为编译依赖项,所以我只是将它复制到我的 Intellij 项目中的 libs 文件夹中。 However, I'm trying to use gradle.但是,我正在尝试使用 gradle。 I only need it as a dependency for ONE of my modules.我只需要它作为我的一个模块的依赖项。 How do I do this.我该怎么做呢。 I currently have this in my module jar task:我目前在我的模块 jar 任务中有这个:

jar {

    from('build/classes/main/')
    from('libs/tools.jar')

    manifest {
        attributes 'Manifest-Version': '1.0',
                'Class-Path': configurations.runtime.files.collect {"../lib/${it.name}" },
}

I also tried this in my module's "dependencies" closure:我也在我的模块的“依赖项”闭包中尝试了这个:

 compile fileTree(dir: 'lib', include: '*.jar')

I also just tried putting the jar on my entire project classpath and it's still not compiling:我也只是尝试将 jar 放在我的整个项目类路径上,但它仍然没有编译:

    classpath ":tools"

Maybe it's correct but my IDE isn't refreshing correctly?也许它是正确的,但我的 IDE 没有正确刷新? I have the plugin already我已经有插件了

apply plugin: 'idea'

and it's been working perfectly until I try to do this.在我尝试这样做之前,它一直运行良好。

EDIT: it's for an annotation processor, so I'm trying to include it in my module jar build and not have other modules depend on it.编辑:它用于注释处理器,所以我试图将它包含在我的模块 jar 构建中,并且没有其他模块依赖它。 Is there a better way to do it than copying the jar?有没有比复制 jar 更好的方法呢?

There is a way to express dependency on tools.jar without copying the jar:有一种方法可以在不复制 jar 的情况下表达对 tools.jar 的依赖:

dependencies {
  compile files("${System.getProperty('java.home')}/../lib/tools.jar")
}

Intellij 2017.1 is able to recognize and import it as a module dependency without issues. Intellij 2017.1 能够毫无问题地将其识别为模块依赖项并将其导入。

It only works when run on JDK though, as bare JRE has no tools.jar included.它只在 JDK 上运行时才有效,因为裸 JRE 不包含 tools.jar。

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

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