Quantcast

gradle junit tests, resources and classpath

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

gradle junit tests, resources and classpath

svaens
Hi all, 

for what I believe may be my final problem for some time, 
I would like a better understanding of what is causing the test resources of my project not to be picked up at runtime (of the junit tests).

For a better understanding of my setup, let me explain;

My projects (which i've been migrating from junit to gradle) have a structure like this:

{projectDir}
{projectDir}/src
{projectDir}/test
{projectDir}/build.gradle

and the output gets placed as usual at:

{projectDir}/build/classes/main
{projectDir}/build/classes/test

I have resources, such as XML files in with my test source files, for example, I have an XML file in the test directory, at some level. 
When I check to see if this XML file is turning up in the build output, at ./build/classes/test/etcetc

it is. No problem there. 

However, when my junit test runs, it is not able to find the xml file which it tries to read on the classpath. 

So, my question is regarding classpath and the junit test run during java build. 

Any idea why it is not working? 

In case it matters, i've modified the working dir for the test run, via

test{
workingDir = new File("${junitWorkingDir}")
}

I wouldn't think this matters, if my file is on the classpath correctly.

My build file looks like this:
----------------------------------

apply plugin: 'java'


sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src'
        }
    }

    test {
        java {
            srcDir 'test'
        }
        resources {
            srcDir 'test'
        }
   
    }
}


test{
workingDir = new File("${junitWorkingDir}")
}

jar{
   manifest.from("src/META-INF/MANIFEST.MF")
}

dependencies { 
testCompile files("${buildLibs}/junit.jar")
testCompile files("${buildLibs}/app.jar")
testCompile project(':general/ModulesTestCaseBase')
compile files("${buildHome}/app.jar")
}



I guess I need to add something to test.runtimeClasspath  but, I don't know why... 


Again, thanks in advance. 
Should I come across the answer by myself, i'll post it for others.

sean





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

Merlyn Albery-Speyer
Hi Sean,

Can you post a snippet of the Java code you're using to access the
files? Also, what value is this set to for your tests?

new File('.').getAbsolutePath()

Cheers,
Merlyn
 
On Mon, 2011-05-23 at 21:11 +1000, Sean Van Buggenum wrote:

> Hi all,
>
>
> for what I believe may be my final problem for some time,
> I would like a better understanding of what is causing the test
> resources of my project not to be picked up at runtime (of the junit
> tests).
>
>
> For a better understanding of my setup, let me explain;
>
>
> My projects (which i've been migrating from junit to gradle) have a
> structure like this:
>
>
> {projectDir}
> {projectDir}/src
> {projectDir}/test
> {projectDir}/build.gradle
>
>
> and the output gets placed as usual at:
>
>
> {projectDir}/build/classes/main
> {projectDir}/build/classes/test
>
>
> I have resources, such as XML files in with my test source files, for
> example, I have an XML file in the test directory, at some level.
> When I check to see if this XML file is turning up in the build
> output, at ./build/classes/test/etcetc
>
>
> it is. No problem there.
>
>
> However, when my junit test runs, it is not able to find the xml file
> which it tries to read on the classpath.
>
>
> So, my question is regarding classpath and the junit test run during
> java build.
>
>
> Any idea why it is not working?
>
>
> In case it matters, i've modified the working dir for the test run,
> via
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> I wouldn't think this matters, if my file is on the classpath
> correctly.
>
>
> My build file looks like this:
> ----------------------------------
>
>
> apply plugin: 'java'
>
>
>
>
> sourceSets {
>     main {
>         java {
>             srcDir 'src'
>         }
>         resources {
>             srcDir 'src'
>         }
>     }
>
>
>     test {
>         java {
>             srcDir 'test'
>         }
>         resources {
>             srcDir 'test'
>         }
>    
>     }
> }
>
>
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> jar{
>    manifest.from("src/META-INF/MANIFEST.MF")
> }
>
>
> dependencies {
> testCompile files("${buildLibs}/junit.jar")
> testCompile files("${buildLibs}/app.jar")
> testCompile project(':general/ModulesTestCaseBase')
> compile files("${buildHome}/app.jar")
> }
>
>
>
>
>
>
> I guess I need to add something to test.runtimeClasspath  but, I don't
> know why...
>
>
>
>
> Again, thanks in advance.
> Should I come across the answer by myself, i'll post it for others.
>
>
> sean
>
>
>
>
>
>
>
>
>
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

svaens

Hi Merlyn, and thanks for the reply.

I am using 

ClassLoader.getResource(String path)

i.e., 

URL url = _clssLoader.getResource(StringHlpr.ltrim(resource_name, "\\/"));

where my helper class function 'StringHlpr.ltrim' trims all consecutive characters (of any characters provided in the 2nd String argument) to the left of the 1st argument
(because the Java classloader function getResource doesn't like slashes in front of the path.

This works no problem when actually running the program, as well as when running the junit test via ant, with in eclipse or standalone.
Only in gradle does it fail.

In looking more closely at the classpath, by printing it out in the logs, I notice that the required URLS are not in the classpath I use:


24-May-2011 11:33:43 svUbuntuX2
SEVERE: classpath has urls of: 
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/antlr-2.7.7.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/GMetrics-0.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-maven-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-sonar-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-antlr-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/bsh-2.0b4.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-ide-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-osgi-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-util-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/checkstyle-5.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/sonar-batch-bootstrapper-2.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-annotations-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/bndlib-1.15.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/servlet-api-2.5-20081211.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-naming-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-jetty-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-plugins-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/testng-5.14.10.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-code-quality-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/commons-beanutils-core-1.8.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jsp-api-2.1-6.1.14.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/junit-4.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-scala-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/CodeNarc-0.13.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jsp-2.1-6.1.14.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/ant-antlr-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/core-3.1.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/geronimo-annotation_1.0_spec-1.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-plus-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jcommander-1.12.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/snakeyaml-1.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-announce-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jansi-1.2.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/logback-classic-0.9.28.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-httpclient-3.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-wrapper-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-ui-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ivy-2.2.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ant-launcher-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/log4j-over-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jna-3.2.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/core-impl/
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jcl-over-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/guava-r08.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jsch-0.1.42.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jna-posix-1.0.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/webdavlib-2.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/dom4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-codec-1.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-tooling-api-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ant-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-io-1.4.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jul-to-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-lang-2.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/groovy-all-1.7.10.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-open-api-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/logback-core-0.9.28.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jaxen-1.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-launcher-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-core-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/slf4j-api-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-cli-1.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jzlib-1.0.7.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/asm-all-3.3.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-collections-3.2.1.jar
file:/mnt/data/bin/java6/jdk1.6.0_24/lib/tools.jar

24-May-2011 11:33:43 svUbuntuX2
SEVERE: End of classpath output

which is strange, because when I iterate over the sourceSets.test.runtimeClasspath fileset, it shows I should have it on my classpath

testClasses.doFirst {

println "Test classpath is:- "
sourceSets.test.runtimeClasspath.getFiles().each { file ->
println "file: \"" + file + "\""
}

}
OUTPUT:
Test classpath is:- 
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/test"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/main"
file: "/mnt/data/dev/svn/working_build/lib/junit.jar"
file: "/mnt/data/dev/svn/working_build/lib/app.jar"
file: "/mnt/data/dev/svn/working_build/app.jar"
file: "/mnt/data/dev/svn/working_build/lib/xstream-1.3.1.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/general/ModulesTestCaseBase/build/libs/general/ModulesTestCaseBase.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/libs/data_export/Project1.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/src/test/resources"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/test"

where the resource I want can be found at the path

file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/test"

(i've checked; it is there!)

So, it could be down to which classloader I am using. However, that's as maybe, I need to restate, It works in ANT in two running environments. Why should it not work in Gradle?
I don't really want to go modifying application code to suit Gradle.

any ideas ? Anyone come across such similar problems with Classpath and classloader?


thanks and regards, 

sean



On 24 May 2011 01:02, Merlyn Albery-Speyer <[hidden email]> wrote:
Hi Sean,

Can you post a snippet of the Java code you're using to access the
files? Also, what value is this set to for your tests?

new File('.').getAbsolutePath()

Cheers,
Merlyn

On Mon, 2011-05-23 at 21:11 +1000, Sean Van Buggenum wrote:
> Hi all,
>
>
> for what I believe may be my final problem for some time,
> I would like a better understanding of what is causing the test
> resources of my project not to be picked up at runtime (of the junit
> tests).
>
>
> For a better understanding of my setup, let me explain;
>
>
> My projects (which i've been migrating from junit to gradle) have a
> structure like this:
>
>
> {projectDir}
> {projectDir}/src
> {projectDir}/test
> {projectDir}/build.gradle
>
>
> and the output gets placed as usual at:
>
>
> {projectDir}/build/classes/main
> {projectDir}/build/classes/test
>
>
> I have resources, such as XML files in with my test source files, for
> example, I have an XML file in the test directory, at some level.
> When I check to see if this XML file is turning up in the build
> output, at ./build/classes/test/etcetc
>
>
> it is. No problem there.
>
>
> However, when my junit test runs, it is not able to find the xml file
> which it tries to read on the classpath.
>
>
> So, my question is regarding classpath and the junit test run during
> java build.
>
>
> Any idea why it is not working?
>
>
> In case it matters, i've modified the working dir for the test run,
> via
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> I wouldn't think this matters, if my file is on the classpath
> correctly.
>
>
> My build file looks like this:
> ----------------------------------
>
>
> apply plugin: 'java'
>
>
>
>
> sourceSets {
>     main {
>         java {
>             srcDir 'src'
>         }
>         resources {
>             srcDir 'src'
>         }
>     }
>
>
>     test {
>         java {
>             srcDir 'test'
>         }
>         resources {
>             srcDir 'test'
>         }
>
>     }
> }
>
>
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> jar{
>    manifest.from("src/META-INF/MANIFEST.MF")
> }
>
>
> dependencies {
> testCompile files("${buildLibs}/junit.jar")
> testCompile files("${buildLibs}/app.jar")
> testCompile project(':general/ModulesTestCaseBase')
> compile files("${buildHome}/app.jar")
> }
>
>
>
>
>
>
> I guess I need to add something to test.runtimeClasspath  but, I don't
> know why...
>
>
>
>
> Again, thanks in advance.
> Should I come across the answer by myself, i'll post it for others.
>
>
> sean
>
>
>
>
>
>
>
>
>
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

Adam Murdoch

On 24/05/2011, at 12:05 PM, Sean Van Buggenum wrote:


Hi Merlyn, and thanks for the reply.

I am using 

ClassLoader.getResource(String path)

i.e., 

URL url = _clssLoader.getResource(StringHlpr.ltrim(resource_name, "<a href="smb:///">\\/"));

What value are you using for _classLoader?



where my helper class function 'StringHlpr.ltrim' trims all consecutive characters (of any characters provided in the 2nd String argument) to the left of the 1st argument
(because the Java classloader function getResource doesn't like slashes in front of the path.

This works no problem when actually running the program, as well as when running the junit test via ant, with in eclipse or standalone.
Only in gradle does it fail.

In looking more closely at the classpath, by printing it out in the logs, I notice that the required URLS are not in the classpath I use:

24-May-2011 11:33:43 svUbuntuX2
SEVERE: classpath has urls of: 
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/antlr-2.7.7.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/GMetrics-0.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-maven-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-sonar-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-antlr-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/bsh-2.0b4.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-ide-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-osgi-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-util-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/checkstyle-5.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/sonar-batch-bootstrapper-2.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-annotations-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/bndlib-1.15.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/servlet-api-2.5-20081211.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-naming-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-jetty-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-plugins-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/testng-5.14.10.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-code-quality-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/commons-beanutils-core-1.8.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jsp-api-2.1-6.1.14.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/junit-4.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-scala-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/CodeNarc-0.13.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jsp-2.1-6.1.14.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/ant-antlr-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/core-3.1.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/geronimo-annotation_1.0_spec-1.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jetty-plus-6.1.25.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/jcommander-1.12.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/snakeyaml-1.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/gradle-announce-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jansi-1.2.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/logback-classic-0.9.28.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-httpclient-3.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-wrapper-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-ui-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ivy-2.2.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ant-launcher-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/log4j-over-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jna-3.2.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/core-impl/
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jcl-over-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/guava-r08.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jsch-0.1.42.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jna-posix-1.0.3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/webdavlib-2.0.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/dom4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-codec-1.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-tooling-api-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/ant-1.8.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-io-1.4.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jul-to-slf4j-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/plugins/
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-lang-2.6.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/groovy-all-1.7.10.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-open-api-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/logback-core-0.9.28.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jaxen-1.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-launcher-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/gradle-core-1.0-milestone-3.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/slf4j-api-1.6.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-cli-1.2.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/jzlib-1.0.7.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/asm-all-3.3.1.jar
file:/mnt/data/bin/gradle-1.0-milestone-3/lib/commons-collections-3.2.1.jar
file:/mnt/data/bin/java6/jdk1.6.0_24/lib/tools.jar

24-May-2011 11:33:43 svUbuntuX2
SEVERE: End of classpath output

which is strange, because when I iterate over the sourceSets.test.runtimeClasspath fileset, it shows I should have it on my classpath

testClasses.doFirst {

println "Test classpath is:- "
sourceSets.test.runtimeClasspath.getFiles().each { file ->
println "file: \"" + file + "\""
}

}
OUTPUT:
Test classpath is:- 
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/test"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/main"
file: "/mnt/data/dev/svn/working_build/lib/junit.jar"
file: "/mnt/data/dev/svn/working_build/lib/app.jar"
file: "/mnt/data/dev/svn/working_build/app.jar"
file: "/mnt/data/dev/svn/working_build/lib/xstream-1.3.1.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/general/ModulesTestCaseBase/build/libs/general/ModulesTestCaseBase.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/libs/data_export/Project1.jar"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/src/test/resources"
file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/test"

where the resource I want can be found at the path

file: "/mnt/data/dev2/workflow/testRelocate/modules_extra/data_export/Project1/build/classes/test"

(i've checked; it is there!)

So, it could be down to which classloader I am using. However, that's as maybe, I need to restate, It works in ANT in two running environments. Why should it not work in Gradle?
I don't really want to go modifying application code to suit Gradle.

any ideas ? Anyone come across such similar problems with Classpath and classloader?


thanks and regards, 

sean



On 24 May 2011 01:02, Merlyn Albery-Speyer <[hidden email]> wrote:
Hi Sean,

Can you post a snippet of the Java code you're using to access the
files? Also, what value is this set to for your tests?

new File('.').getAbsolutePath()

Cheers,
Merlyn

On Mon, 2011-05-23 at 21:11 +1000, Sean Van Buggenum wrote:
> Hi all,
>
>
> for what I believe may be my final problem for some time,
> I would like a better understanding of what is causing the test
> resources of my project not to be picked up at runtime (of the junit
> tests).
>
>
> For a better understanding of my setup, let me explain;
>
>
> My projects (which i've been migrating from junit to gradle) have a
> structure like this:
>
>
> {projectDir}
> {projectDir}/src
> {projectDir}/test
> {projectDir}/build.gradle
>
>
> and the output gets placed as usual at:
>
>
> {projectDir}/build/classes/main
> {projectDir}/build/classes/test
>
>
> I have resources, such as XML files in with my test source files, for
> example, I have an XML file in the test directory, at some level.
> When I check to see if this XML file is turning up in the build
> output, at ./build/classes/test/etcetc
>
>
> it is. No problem there.
>
>
> However, when my junit test runs, it is not able to find the xml file
> which it tries to read on the classpath.
>
>
> So, my question is regarding classpath and the junit test run during
> java build.
>
>
> Any idea why it is not working?
>
>
> In case it matters, i've modified the working dir for the test run,
> via
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> I wouldn't think this matters, if my file is on the classpath
> correctly.
>
>
> My build file looks like this:
> ----------------------------------
>
>
> apply plugin: 'java'
>
>
>
>
> sourceSets {
>     main {
>         java {
>             srcDir 'src'
>         }
>         resources {
>             srcDir 'src'
>         }
>     }
>
>
>     test {
>         java {
>             srcDir 'test'
>         }
>         resources {
>             srcDir 'test'
>         }
>
>     }
> }
>
>
>
>
> test{
> workingDir = new File("${junitWorkingDir}")
> }
>
>
> jar{
>    manifest.from("src/META-INF/MANIFEST.MF")
> }
>
>
> dependencies {
> testCompile files("${buildLibs}/junit.jar")
> testCompile files("${buildLibs}/app.jar")
> testCompile project(':general/ModulesTestCaseBase')
> compile files("${buildHome}/app.jar")
> }
>
>
>
>
>
>
> I guess I need to add something to test.runtimeClasspath  but, I don't
> know why...
>
>
>
>
> Again, thanks in advance.
> Should I come across the answer by myself, i'll post it for others.
>
>
> sean
>
>
>
>
>
>
>
>
>
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

Marco Hunsicker
In reply to this post by svaens
> So, it could be down to which classloader I am using. However, that's as
> maybe, I need to restate, It works in ANT in two running environments. Why
> should it not work in Gradle?

Because Ant != Gradle? ;)

Otherwise you are right on track. You are using the wrong classloader.
The first bunch of urls belong to the classloader of the calling class,
the main Gradle classloader. You want to use one that covers the urls of
the source set. It's a common trap because of a poor classloader model
that will hopefully get addressed in a future Gradle release.

There might be no way around it other than to adjust your code. As has
been asked before: how do you get access to the classloader?

Cheers,

Marco

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

svaens
Hi Marco, Adam, 

I appreciate your patience, in responding to someone who must come across quite poorly. 
It is pure frustration. And if I was not able to reign it in, in my email, I am sorry. 
Now, to the issue:

The question; "how do (I) get access to the classloader" is not a simple one.
I am involved in the development of an application which;
1. loads its own .jar plugins
2. of which can have other dynamic .jar dependencies, specified in a XML descriptor resource file found in plugin .jar 1 

it all gets a bit complicated, and so the classLoader resolution is similarly complicated. 
It iterates over the calling stack, and if it finds such a calling classes classloader where this classloader is a descendant of the current thread context ClassLoader,  we use this. 
If not, we use the current-thread context-classloader itself
i.e. final ClassLoader threadContextLoader = Thread.currentThread ().getContextClassLoader();
and in very rare problem conditions, the system class loader might be used.
In otherwords, the classloader is chosen on the fly, programatically, depending on conditions.

So, I debugged the junit test, as it run via ANT, and noticed that in that environment, it just uses the current-thread context classLoader. 
So, as a work-around, in order to get things working for gradle, i make sure it is possible just to use the current-thread context-classloader.

Now those junit tests run in Gradle. However, I've got some re-coding to do before I can be confident of it working in all situations.... 
More motivation to write more junit tests I guess..... although, I would be then testing for error situations that only occur in gradle. 

I am definitely not a top java coder. But .... .geez.... regardless, classpath problems really stink. 

Kind Regards, 

Sean




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gradle junit tests, resources and classpath

jaydatt
Hi Svaens,

I am in the similar kind of situation, In my case as well the sr/test/resouces are not getting read while i execute my JUnit test case using gradle.

However I figured out that, the test/resources are not getting copied to the "build/resources" folder  and this is the reason its not getting read.

One alternate solutions is you can add your test resources to your source tree like:

sourceSets {
     main {
        resources.srcDirs += ['src/test/resources']
   }
}

and this will definitly solve your problem, however this is not the proper solution...
so, Did you get your problem resolved on a proper way?
If yes than please let me know the solutions, it will be really appreciable
Loading...