title: JAR file library included using Gradle fileTree isn’t being seen by Java code
body: <p>I created a new Java project in IntelliJ IDEA using its Gradle project template, and I am trying to set up a library so that my project can use it. I saved the library JAR file to <code>./libs/frink-2014-02-17.jar</code> in the project. In the <code>dependencies</code> section of my <code>build.gradle</code>, I wrote <code>runtime fileTree(dir: 'libs', include: '*.jar')</code>. But my Java code cannot see that library.  When I try to build the project, the compiler complains that <code>import frink.parser.Frink;</code> references a package that does not exist.</p>
  
  <p>How can I fix my build errors, so that I can use the Frink library in my Java project?</p>
  
  <h2>Details</h2>
  
  <p>The library is <a href="http://futureboy.us/frinkdocs/" rel="nofollow">Frink</a>. Frink is <a href="http://search.maven.org/#search|ga|1|frink" rel="nofollow">not in the Maven repository</a>, so I <a href="http://futureboy.us/frinkdocs/#DownloadingFrink" rel="nofollow">downloaded its JAR file</a>, renamed it so it has the version in the filename (following <a href="http://www.gradle.org/docs/current/userguide/userguide_single.html#sub%3aversioning_the_jar_name" rel="nofollow">the recommendation of the Gradle docs</a>), and put it in a <code>libs</code> folder at the root of the project. Then I copied the following line of code from <a href="http://www.gradle.org/docs/current/userguide/userguide_single.html#sub%3afile_dependencies" rel="nofollow">Gradle User Guide: File dependencies</a> to try to include all JAR files in that <code>libs</code> directory I created:</p>
  
  <pre class="lang-java prettyprint-override"><code>runtime fileTree(dir: 'libs', include: '*.jar')
  </code></pre>
  
  <p>But when I “Make Project”, or run <code>./gradlew build</code>, I get these errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>/…/frink-soulver/src/main/java/Main.java:1: package frink.parser does not exist
  import frink.parser.Frink;
                     ^     
  /…/frink-soulver/src/main/java/Main.java:5: cannot find symbol
  symbol  : class Frink    
  location: class Main     
          Frink interp = new Frink();
          ^                
  /…/frink-soulver/src/main/java/Main.java:5: cannot find symbol
  symbol  : class Frink    
  location: class Main     
          Frink interp = new Frink();
                             ^
  /…/frink-soulver/src/main/java/Main.java:11: package frink.errors does not exist
          } catch (frink.errors.FrinkEvaluationException fee) {
                               ^
  4 errors                 
  :compileJava FAILED
  </code></pre>
  
  <p>My IDE highlights the same errors when I open and view <code>Main.java</code>, before I compile it.</p>
  
  <p>My code in <code>Main.java</code>, including the <code>import</code>, is just <a href="http://futureboy.us/frinkdocs/#EmbeddingFrink" rel="nofollow">the Frink sample code</a>. And the <a href="http://futureboy.us/frinkdocs/integrate/" rel="nofollow">Frink online JavaDocs</a> indicate that there indeed should be a <code>frink.parser</code> package in that JAR file. So it’s not that I’m asking for a package that doesn’t exist.</p>
  
  <p>I have tried changing <code>runtime</code> to <code>compile</code> in <code>build.gradle</code>, but that didn’t make a difference.</p>
  
  <p>When I open “Project Structure…” in IDEA and go to the Libraries section, the Frink JAR file is missing from that list. The list contains “Gradle: guava-12.0”, “Gradle: hamcrest-core-1.3”, “Gradle: jsr305-2.0.3”, and “Gradle: junit-4.11”. I don’t want to just click the + button to add a library using IDEA, because I think it would be confusing to have libraries included in two separate ways.</p>
  
  <p>I’ve <a href="https://www.google.com/search?q=Gradle+fileTree" rel="nofollow">searched for “Gradle fileTree”</a>, but it looks like I’m using <code>fileTree</code> the same way as in those results.</p>
  
  <p>I’m new to Gradle, IDEA, and setting up Java projects from scratch. So if any of my project setup seems weird or nonstandard, I am open to corrections. For example, if there’s a better way to include Frink than copying its JAR file into a folder in my project, I can do that.</p>
  
  <h2>Detailed project contents</h2>
  
  <p>My full <code>build.gradle</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>apply plugin: 'java'
  
  sourceCompatibility = 1.6
  version = '1.0'
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      testCompile group: 'junit', name: 'junit', version: '4.11'
  
      /* commenting this out for the question because the error still happens without this
      // http://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild
      runtime group: 'com.google.guava', name: 'guava', version: '12.0'
      // http://stackoverflow.com/questions/10007994/why-do-i-need-jsr305-to-use-guava-in-scala/10013226#10013226
      // I'll include this dependency in case I decide I want to use these annotations
      compile group: 'com.google.code.findbugs', name: 'jsr305', version: '2.0.3'
      */
  
      runtime fileTree(dir: 'libs', include: '*.jar')
  }
  </code></pre>
  
  <p>My project file tree, as generated by <code>tree</code>:</p>
  
  <pre class="lang-none prettyprint-override"><code>.
  ├── build
  │   ├── classes
  │   │   └── main
  │   └── dependency-cache
  ├── build.gradle
  ├── frink-soulver.iml
  ├── gradle
  │   └── wrapper
  │       ├── gradle-wrapper.jar
  │       └── gradle-wrapper.properties
  ├── gradlew
  ├── gradlew.bat
  ├── libs
  │   └── frink-2014-02-17.jar
  ├── out
  │   ├── production
  │   │   └── frink-soulver
  │   └── test
  │       └── frink-soulver
  └── src
      ├── main
      │   ├── java
      │   │   └── Main.java
      │   └── resources
      └── test
          ├── java
          └── resources
  </code></pre>
  
  <p>My full <code>Main.java</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>import frink.parser.Frink;
  
  public class Main {
      public static void main(String[] args) {
          Frink interp = new Frink();
          interp.setRestrictiveSecurity(true);
  
          try {
              String results = interp.parseString("2+2");
              System.out.println(results);
          } catch (frink.errors.FrinkEvaluationException fee) {
              // Do whatever you want with the exception
          }
      }
  }
  </code></pre>