./gradlew clean assemble
Gradle Version : 4.5.1
OS Info : Linux 4.4.114-94.11-default (amd64)
JDK Version : Oracle Corporation 9.0.4 [Java HotSpot(TM) 64-Bit Server VM 9.0.4+11]
JAVA_HOME : /usr/java/jdk-9.0.4
Declaring a dependency in the api configuration of a java library does export it to consuming projects, but that is a different concept from bundling an application with its dependencies. Fat JARs are generally bad for libraries, but good for applications. To bundle dependencies, you can use a plugin like Shadow.
If your JAR file runs with java -jar when using Java 8, your build must already contain a plugin or logic to handle building a fat JAR or the full required classpath. You would encounter java.lang.ClassNotFoundException for dependencies if you were trying to run the JAR that would be built by default.
Your later mention of Java 9 instead suggests you’re having a Java 9 module issue, but it isn’t clear what you’ve done to set up for Java 9 or if you’ve followed some steps from the Gradle guides on Java 9 modules. Please clarify what you have in your project.