0

I am running the automation test Project in Gradle and I need to call one Java Program for the Report Generation at the end of the test completion .So, I have created one task to execute the Java program as per (Gradle to execute Java class (without modifying build.gradle)).

Gradle Task:

task reportGenerator(type:JavaExec){
   classpath = sourceSets.main.runtimeClasspath
  main = "util.Result_Generator"
}

But unfortunately , I am getting an error as Error: Could not find or load main class util.Result_Generator

I have validated Java Environment Variable and it is also correct. Could you please help me to solve?

  • Where is the source file containing `Result_Generator` located? Could you post your entire directory structure? – Lukas Körfer Jun 01 '18 at 16:59
  • 1
    is Result_Generator part of src/main or src/test? From your purpose it seems like it is part of src/test, which will not be part of sourceSets.*main*.runtimeClasspath – gagan singh Jun 01 '18 at 23:14
  • Result_Generator main class resides in src/test.Now it is working after changing the classpath as sourceSets.test.runtimeClasspath –  Jun 02 '18 at 16:50

1 Answers1

0

System is not able to find the main class in the mentioned classpath. There could be any one of the below reasons. Please validate all the below

  1. Check Whether the main class name is correct (Including the package name)
  2. Check whether the Result_Generator file is available in src/main
  3. If the Result_Generator file is available in src/test instead of src/main, then the classpath needs to be changed as classpath = sourceSets.test.runtimeClasspath and specify the class name correctly.
Subburaj
  • 2,294
  • 3
  • 20
  • 37
  • It is working after changing the classpath as sourceSets.test.runtimeClasspath –  Jun 02 '18 at 16:51