Hi, I am new to gradle projects. My task when run, can’t find the junit related classes nor the main method. I want to use the junit that is bundled as a jar in the lib folder. I have a project structure like this -
test
------lib
------junit-4.4.jar(with other jar files)
------code.jar
Here is my code -
apply plugin: 'java'
repositories {
flatDir{
dirs 'D:/test/lib'
}
}
dependencies {
compile group: 'junit', name: 'junit', version: '4.4'
}
task runTest(type:JavaExec){
main = 'com.org.mainMethod'
classpath = files([repositories.flatDir,'D:/test/code.jar','D:/test/lib'])
}
The task fails because it cannot find the junit related files. I am completely lost now -
java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class:com.org.mainMethod
Program will exit.
Any help is appreciated.