Why can't I simply build this gradle with jsoup dependency and run it?

I just built a simple java project with this gradle file:

apply plugin: 'java'

allprojects {
    sourceCompatibility = 1.7
    targetCompatibility = 1.7

repositories {

dependencies {
    compile 'org.jsoup:jsoup:1.8.3'

then, it generates:


where build is inside workspace

I then run java -cp build/classes/main MainSisgrad and it works, but when it come to the part of the jsoup interpretation, I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup   

Note that the folder build/libs has a file names workspace.jar, whats is it? Is it a .jar with all the libs compiled? Including jsoup? Because I tried to include it in the classpath like this:

java -cp build/libs/workspace.jar -cp build/classes/main MainSisgrad 


java -cp build/libs/ -cp build/classes/main MainSisgrad 

but it didn’t work. What’s missing?

What’s missing?

Gradle’s java plugin just creates a jar. In particular, it does not automatically bundle the dependencies for you.

Have a look at the application plugin The Application Plugin which is probably what you are looking for.

If you are looking to create a single jar, have a look at the shadow plugin.

but where I’d put that it’s a java program? Or I put this below “apply plugin: java”?

Copy this: https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/application/build.gradle