You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by jlo_gestalt <jl...@gestalt-llc.com> on 2008/05/16 16:40:36 UTC

Test classpath issue with v2.0.8 and v2.0.9

When trying to access test resources in my unit tests, maven 2.0.8 and above
are returning the wrong directory.

Here is my basic code to access the folder
def file = new JmblXsltDriverTest().getClass().getResource("/")?.file
println file

On 2.0.7 this would print
/workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/test-classes/

On 2.0.8 and 2.0.9 this prints
/workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/classes/

To me this is a critical bug that would almost certainly cause every
projects unit tests that access test resources to fail.


-- 
View this message in context: http://www.nabble.com/Test-classpath-issue-with-v2.0.8-and-v2.0.9-tp17276386p17276386.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Test classpath issue with v2.0.8 and v2.0.9

Posted by Dan Fabulich <da...@fabulich.com>.
jlo_gestalt wrote:

>
> When trying to access test resources in my unit tests, maven 2.0.8 and above
> are returning the wrong directory.
>
> Here is my basic code to access the folder
> def file = new JmblXsltDriverTest().getClass().getResource("/")?.file
> println file
>
> On 2.0.7 this would print
> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/test-classes/
>
> On 2.0.8 and 2.0.9 this prints
> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/classes/
>
> To me this is a critical bug that would almost certainly cause every
> projects unit tests that access test resources to fail.

I'm going to guess you're encountering the bug described here:
http://docs.codehaus.org/display/MAVENUSER/Classpath+Ordering+Bugs+in+Maven+Surefire

Upgrading Surefire will probably restore you to the correct behavior.

-Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Test classpath issue with v2.0.8 and v2.0.9

Posted by jlo_gestalt <jl...@gestalt-llc.com>.
I disagree with you on accessing the resources my way, but that is for
another post.

Anyways, I was able to upgrade to maven 2.0.8 and surefire plugin 2.4.3 and
things worked as expected. The only unfortunate thing is that now it won't
work on maven 2.0.7, but oh well.


Clifton wrote:
> 
> I have a couple of observations... First off I see you're writing you unit
> tests in Groovy! That's a good thing of course for far too many reasons.
> It's also an important detail to pay attention to. There are a hole host
> of other details to look at as well. Secondly it appears you are trying to
> query for the resource folder using code. This is not a good thing or a
> necessary thing to do. Maven will put all of your "test resources" under
> the test-classes folder unless something else somewhere else tells it not
> to. Another detail is that your code is asking the wrong question and may
> have been mistakenly getting at the right answer all along. It asks the
> location of it's execution folder not the location of the resource folder.
> I can show you the correct hack to locating the resource folder involving
> a marker file which you could run and arrive at a more accurate answer.
> More on that later. Here's the important things to consider. Groovy is
> interpreted/compiled. Running that same groovy code through a plugin (like
> the Groovy plugin or Ant run) would place compiled classes in your classes
> output folder. In one case I'm assuming the code was being copied from the
> test/resources to the test-classes folder and in another case it is
> possibly being filtered. I can't tell without looking.
> 
> Here's some things to look for. Find out where the Groovy code is being
> run from. Is it being both compiled to target/classes and copied over to
> target/test-classes as .groovy files? If so then there's some ambiguity
> worth cleaning up. What is it you are actually trying to do? Do you want
> to run the scripts or do you want to compile them? If you are compiling
> them make sure you point the compiler to the correct output folder.
> 
> I feel like I'm babbling and confusing you more than helping but I'm sure
> your problem lies in whther you compile to the correct output folder or
> copy to the correct output folder. Look for filters that may have been
> added as well.
> 
> jlo_gestalt wrote:
>> 
>> When trying to access test resources in my unit tests, maven 2.0.8 and
>> above are returning the wrong directory.
>> 
>> Here is my basic code to access the folder
>> def file = new JmblXsltDriverTest().getClass().getResource("/")?.file
>> println file
>> 
>> On 2.0.7 this would print
>> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/test-classes/
>> 
>> On 2.0.8 and 2.0.9 this prints
>> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/classes/
>> 
>> To me this is a critical bug that would almost certainly cause every
>> projects unit tests that access test resources to fail.
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Test-classpath-issue-with-v2.0.8-and-v2.0.9-tp17276386p17283178.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Test classpath issue with v2.0.8 and v2.0.9

Posted by Clifton <cl...@gmail.com>.
I have a couple of observations... First off I see you're writing you unit
tests in Groovy! That's a good thing of course for far too many reasons.
It's also an important detail to pay attention to. There are a hole host of
other details to look at as well. Secondly it appears you are trying to
query for the resource folder using code. This is not a good thing or a
necessary thing to do. Maven will put all of your "test resources" under the
test-classes folder unless something else somewhere else tells it not to.
Another detail is that your code is asking the wrong question and may have
been mistakenly getting at the right answer all along. It asks the location
of it's execution folder not the location of the resource folder. I can show
you the correct hack to locating the resource folder involving a marker file
which you could run and arrive at a more accurate answer. More on that
later. Here's the important things to consider. Groovy is
interpreted/compiled. Running that same groovy code through a plugin (like
the Groovy plugin or Ant run) would place compiled classes in your classes
output folder. In one case I'm assuming the code was being copied from the
test/resources to the test-classes folder and in another case it is possibly
being filtered. I can't tell without looking.

Here's some things to look for. Find out where the Groovy code is being run
from. Is it being both compiled to target/classes and copied over to
target/test-classes as .groovy files? If so then there's some ambiguity
worth cleaning up. What is it you are actually trying to do? Do you want to
run the scripts or do you want to compile them? If you are compiling them
make sure you point the compiler to the correct output folder.

I feel like I'm babbling and confusing you more than helping but I'm sure
your problem lies in whther you compile to the correct output folder or copy
to the correct output folder. Look for filters that may have been added as
well.

jlo_gestalt wrote:
> 
> When trying to access test resources in my unit tests, maven 2.0.8 and
> above are returning the wrong directory.
> 
> Here is my basic code to access the folder
> def file = new JmblXsltDriverTest().getClass().getResource("/")?.file
> println file
> 
> On 2.0.7 this would print
> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/test-classes/
> 
> On 2.0.8 and 2.0.9 this prints
> /workspace/checkout/weather/trunk/jetjwis/jbi/jmbl-xslt/target/classes/
> 
> To me this is a critical bug that would almost certainly cause every
> projects unit tests that access test resources to fail.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Test-classpath-issue-with-v2.0.8-and-v2.0.9-tp17276386p17281319.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org