maiflai / gradle-scalatest

A plugin to enable the use of scalatest in a gradle Scala project.
The Unlicense
73 stars 35 forks source link

Error: Could not find or load main class org.scalatest.tools.Runner #82

Closed sjmittal closed 4 years ago

sjmittal commented 4 years ago

Hi, I am trying to run tests, but it fails with error Error: Could not find or load main class org.scalatest.tools.Runner

My gradle version is:

------------------------------------------------------------
Gradle 5.2
------------------------------------------------------------

Build time:   2019-02-04 11:16:48 UTC
Revision:     840644a429c8b8b9ae399867eb1660e3109bc7a3

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_60 (Oracle Corporation 25.60-b23)
OS:           Windows 10 10.0 amd64

In my build.gradle I have defined the following settings: apply plugin: 'com.github.maiflai.scalatest' testRuntime 'org.pegdown:pegdown:1.1.0'

Also before the execution of tests if I print the classpath entries using: configurations.testRuntime.each { println it }

I see an entry: org.scalatest\scalatest_2.11\3.0.0\5cd41e3452a015179356ab30de4440ae7dc999f8\scalatest_2.11-3.0.0.jar So looks like scala test is in the class path which contains the main class that could not be found.

I also see the entry org.pegdown\pegdown\1.6.0\231ae49d913467deb2027d0b8a0b68b231deef4f\pegdown-1.6.0.jar

Is there any specific entry I need to check in my classpath to ensure all the classes are loaded?

I am confused as to why the test task is failing.

Any help please?

maiflai commented 4 years ago

Sorry for the delay.

I wonder if you have a very long classpath? It might explain why some classes are not found on Windows.

sjmittal commented 4 years ago

@maiflai There is indeed an issue with gradle on this: https://github.com/gradle/gradle/issues/1989

However I did a workaround for this using solutions provided in: https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle

Also as mentioned before when I print the classpath entries using: configurations.testRuntime.each { println it }

I do find the jar responsible for loading org.scalatest.tools.Runner. Maybe I am not printing classpath correctly.

Can you confirm at your end that what classpath should get printed and right way of printing it.

maiflai commented 4 years ago

There are several solutions in that link, and I think I would use different techniques to inspect the classpath in each one.

I think that you would find that exception if org.scalatest.tools.Runner or any dependencies of it were missing, so it is not sufficient to simply check for the scalatest jar.

There are JVM options to verbosely print the discovery of classes, but it may be simpler to upgrade to Gradle 6?

sjmittal commented 4 years ago

@maiflai Thanks for the input. I was able to figure out what was missing in my classpath and now test cases are running fine. This can be closed.

maiflai commented 4 years ago

Glad to hear it - what was the problem in the end please?

sjmittal commented 4 years ago

The problem was basically the pathing jar I had created to solve long classpath issue was not referencing all the dependencies and as you had pointed that it would give error for org.scalatest.tools.Runner even if some of the dependencies are not getting loaded. That made me check if all the dependencies are getting referenced or not and it fixed the issue.

maiflai commented 4 years ago

Ah, ok. Thanks very much for confirming.