Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 750
Preston Garno Avatar asked Mar 25 '17 22:03

Preston Garno


People also ask

What is Buildscript in Gradle?

The "buildscript" configuration section is for gradle itself (i.e. changes to how gradle is able to perform the build). So this section will usually include the Android Gradle plugin. Follow this answer to receive notifications.

What is classpath in Gradle?

A configuration is simply a named set of dependencies. The compile configuration is created by the Java plugin. The classpath configuration is commonly seen in the buildSrc {} block where one needs to declare dependencies for the build. gradle, itself (for plugins, perhaps).


1 Answers

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.

like image 90
Jk1 Avatar answered Sep 20 '22 03:09

Jk1