title: JavaFX package does not exist in JDK 1.9 compiling to 1.8
body: <p>I have a JavaFX project that I would want to compile to a jar such that JRE 8 and above are able to run the jar. I am using Intellij IDEA 2017 CE, running on a Mac, using JDK 9.0.1 as my project SDK.</p>
  
  <p>The project compiles fine for the following gradle settings:</p>
  
  <pre><code>sourceCompatibility = 1.9
  targetCompatibility = 1.9
  </code></pre>
  
  <p>However, when I tweak the target compatibility to <code>1.8</code>:</p>
  
  <pre><code>sourceCompatibility = 1.9
  targetCompatibility = 1.8
  </code></pre>
  
  <p>It shows a stream of errors relating to a missing JavaFX library:</p>
  
  <pre><code>Error:(1, 26) java: package javafx.application does not exist
  Error:(2, 23) java: package javafx.geometry does not exist
  Error:(3, 23) java: package javafx.geometry does not exist
  Error:(4, 20) java: package javafx.scene does not exist
  Error:(5, 28) java: package javafx.scene.control does not exist
  ...
  </code></pre>
  
  <p>I looked at other stackoverflow answers to see why this is happening such as:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/35974003/javafx-comes-with-jdk-8">JavaFX comes with JDK 8?</a>
  Says JavaFX is bundled with JDK 1.8 but I am using JDK 1.9.</li>
  <li><a href="https://stackoverflow.com/questions/18547362/javafx-and-openjdk">JavaFX and OpenJDK</a> Says OpenJDK has JavaFX, but I am not using OpenJDK</li>
  <li><a href="https://stackoverflow.com/questions/27178895/cannot-resolve-symbol-javafx-application-in-intellij-idea-ide">cannot resolve symbol javafx.application in IntelliJ Idea IDE</a> Says OpenJDK does not have JavaFX (what?), but I am not using OpenJDK</li>
  </ol>
  
  <p>I have also tried to invalidate the caches before building the project but to no avail.</p>
  
  <p>How do I compile to JRE 8 with my JDK?</p>