6

I need the com.sun.tools jar as a compile dependency, so I just copied it to my libs folder in my Intellij project. However, I'm trying to use 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 {

    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:

    classpath ":tools"

Maybe it's correct but my IDE isn't refreshing correctly? 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. Is there a better way to do it than copying the jar?

Preston Garno
  • 1,085
  • 10
  • 26
  • [This](http://stackoverflow.com/a/20956456/104891) should work. In IntelliJ IDEA it should be enough to have `tools.jar` in the JSDK configuration classpath. – CrazyCoder Mar 26 '17 at 07:11
  • @CrazyCoder, nah, figured it out though. I'll post the answer in the morning thought thanks – Preston Garno Mar 26 '17 at 07:15

1 Answers1

7

There is a way to express dependency on tools.jar without copying the 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.

It only works when run on JDK though, as bare JRE has no tools.jar included.

Jk1
  • 10,266
  • 9
  • 49
  • 63