NoClassDefFoundError while handling asm dependency with gradle

When I tried to use gradle to build a program using asm package, I got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
    at analysis.CCMetric.main(CCMetric.java:5)
Caused by: java.lang.ClassNotFoundException:org.objectweb.asm.ClassVisitor
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

My gradle script is as follow:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = 'analysis.CCMetric'

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }    
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile 'org.ow2.asm:asm-all:5.0.2'
    compile 'commons-io:commons-io:2.4'
    compile 'org.jgrapht:jgrapht-core:0.9.1'
    compile 'asm:asm:3.3.1'
}

jar {
    manifest {
        attributes 'Main-Class': 'analysis.CCMetric'
    }
    baseName = 'CCMetric'
    version = '1.0.0'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

I used gradle build to build the project and I run the jar file with java -jar build/libs/CCMetric.jar and then I got the exception as above.

You will also have to provide the external JARs you are depending on when executing the Java command. Gradle does not hook into the Java command magically and provide the external libraries. A good alternatively you can look into is the Application plugin which does something you are looking for out-of-the-box with the run task.

Thank you for your solution, it works for me, just need to specify the arguments within the run task. Thank you again for your help.