Note that there are some explanatory texts on larger screens.

plurals
  1. POClasspath problems when running JUnit tests from Eclipse with Gradle build
    primarykey
    data
    text
    <p>I have a Gradle project that declares a test-only dependency on an XML data file, and then loads the file from the classpath. When I run the tests directly in Gradle from the command line, everything works fine, but when I run "gradlew eclipse", refresh the project in Eclipse, and then try running the test from Eclipse (Debug As -> JUnit Test), the test fails because it's unable to find the XML file and the classpath (as accessed from the Properties context menu item on the process in the Debug view) shows no indication of the XML file being included on the classpath.</p> <p>The behavior I'm seeing has some commonality with <a href="http://gradle.1045684.n5.nabble.com/gradle-junit-tests-resources-and-classpath-td4418753.html#a4420758" rel="nofollow">http://gradle.1045684.n5.nabble.com/gradle-junit-tests-resources-and-classpath-td4418753.html#a4420758</a>, but Sean's problem was the reverse: his tests ran properly under Ant (but he never mentioned trying to run directly from the Eclipse JUnit plugin), but not under Gradle.</p> <p>Here's the relevant part of build.gradle:</p> <blockquote> <p>dependencies { testCompile group: 'com.mycompany', name: 'MyConfigFile', version: '0.0.0+dirty', ext: 'xml' }</p> </blockquote> <p>Because the only resources that URLClasspathLoader can load directly from the file system are JARs, I'm using the following static method to search the classpath for files that match the filename I need to load:</p> <pre><code>public static String getFullPathForResourceDirectlyOnClasspath(String nameFragment) { ClassLoader cl = ClassLoader.getSystemClassLoader(); for (URL url: ((URLClassLoader)cl).getURLs()){ String fullPath = url.getFile(); if (fullPath.contains(nameFragment)) { return fullPath; } } return null; } </code></pre> <p>I call that method as follows:</p> <p><code>getFullPathForResourceDirectlyOnClasspath("/MyConfigFile-");</code></p> <p>When I run that code from Gradle ("gradlew build"), it finds the file and my test succeeds. When I run it from Eclipse (Debug As -> JUnit Test), it fails to find that file on the classpath (because the Eclipse JUnit plugin doesn't put it there) and that call returns null.</p> <p>I've tried changing the configuation from testCompile to compile to see if that made a difference, but it doesn't change anything (and perhaps tellingly, my .classpath doesn't have any entry for the XML file even when the compile configuration is selected).</p> <p>Does anyone know of a way to make this work? Am I just missing something that should be obvious? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload