0

I am using Cucumber framework for mobile app testing. In pom.xml, I have given this below plugin to run TestClass.java - which has code for uploading the latest APK version of the app. Main method is present inside this TestClass. I need this to run before the actual test execution. So I have used exec plugin. I'm getting this error if I am running with pom.xml --> mvn clean test. ClassNotFoundExpection is always thrown with pom.xml, but the individual class runs perfectly.

pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
       <executions>
    <execution>
            <id>installAPK</id>
            <phase>generate-test-sources</phase>
            <goals>
            <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includePluginDependencies>true</includePluginDependencies>
        <mainClass>org.com.package1.TestClass</mainClass>
    </configuration>
</plugin>

Console error:

java.lang.ClassNotFoundException: org.com.package1.TestClass
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:246)
    at java.lang.Thread.run(Thread.java:748)

I also tried changing the phase after test-compile. Still i am getting the same error. Someone pls help.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mitsuhaki
  • 1
  • 4

1 Answers1

1

According to the exec-maven-plugin documentation, the default dependency scope for the execution is runtime. Please change it to test with the following configuration if the TestClass is part of the test sources.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    ...
  </executions>
  <configuration>
    ...
    <classpathScope>test</classpathScope>
  </configuration>
</plugin>
Illya Kysil
  • 1,642
  • 10
  • 18
  • Just a query. If I am having the TestClass at src/main/java without adding this will this work? – Mitsuhaki Oct 20 '21 at 10:58
  • Yes, default dependency scope for the execution is `runtime`, which includes main classes and compile/runtime dependencies. – Illya Kysil Oct 26 '21 at 13:46