You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ryan Moquin <fr...@gmail.com> on 2007/08/08 21:15:54 UTC

Relationship of resources and testResources

If I have this in my pom:

....
<build>
<resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>/src/test/resources</directory>
      </testResource>
    </testResources>
</build>
....

If I have a file such as hibernate.cfg.xml in both locations, but with
different parameters... which one will take precedence during unit tests?
>From I can see, it seems like only the one in the src/main/resources takes
effect.

Do you have to do anything specific to make this work how I would expect?

Thanks.

Re: Relationship of resources and testResources

Posted by Ryan Moquin <fr...@gmail.com>.
Interesting, when I remove the file in the src/main/resources then the one
in src/test/resources gets picked up... I've been playing with it for an
hour and a half.. checking and double checking and it appears as though main
resources is overriding the test resources.  I never had this problem
before. I'm starting to wonder if there are weird classloading stuff going
on depending on what jar is trying to access a resource.

On 8/8/07, Eric Redmond <er...@gmail.com> wrote:
>
> testResources files get copied to the testOutputDirectory. Using surefire,
> the testOutputDirecotry files should take precedence.
>
> --
> Eric Redmond
> http://blog.propellors.net
>
> On 8/8/07, Ryan Moquin <fr...@gmail.com> wrote:
> >
> > If I have this in my pom:
> >
> > ....
> > <build>
> > <resources>
> >       <resource>
> >         <directory>src/main/resources</directory>
> >       </resource>
> >     </resources>
> >     <testResources>
> >       <testResource>
> >         <directory>/src/test/resources</directory>
> >       </testResource>
> >     </testResources>
> > </build>
> > ....
> >
> > If I have a file such as hibernate.cfg.xml in both locations, but with
> > different parameters... which one will take precedence during unit
> tests?
> > From I can see, it seems like only the one in the src/main/resources
> takes
> > effect.
> >
> > Do you have to do anything specific to make this work how I would
> expect?
> >
> > Thanks.
> >
>

Re: Relationship of resources and testResources

Posted by Ryan Moquin <fr...@gmail.com>.
Ahhhhh thanks... man that was really frustrating.  I think I have been
bitten by this before with my persistence.xml and just assumed it was
hibernates fault.  Now I'm thinking it was this as well.

Thanks for getting this off my mind.

On 8/8/07, Max Bowsher <ma...@ukf.net> wrote:
>
> Eric Redmond wrote:
> > testResources files get copied to the testOutputDirectory. Using
> surefire,
> > the testOutputDirecotry files should take precedence.
>
> Actually, no. In Maven 2.0.7 and below, the main output directory takes
> precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.
>
> Compare the getTestClasspathElements method in:
>
>
> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
>
> http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
>
> Max.
>
>
>

Re: Relationship of resources and testResources

Posted by Ryan Moquin <fr...@gmail.com>.
Ok, I'd prefer to stay away from it then since these kinds of problems are
killer on my development schedule.  I do look forward to when a new version
of Maven comes out though and can't wait to see what it's in 2.1.

On 8/9/07, Eric Redmond <er...@gmail.com> wrote:
>
> Well, 2.1 is a lot cooler than 2.0.x - however, I would tend to stay away
> for now unless you want to get involved in the core - it's not THAT
> stable.
> At least wait until the alpha release, which should be coming around in a
> month or so.
>
> --
> Eric Redmond
> http://blog.propellors.net
>
> On 8/8/07, Ryan Moquin <fr...@gmail.com> wrote:
> >
> > Oh you run 2.1?  Do you build it from source?  I tend to try to stay
> away
> > from non-stable builds unless there is a feature I really need, so that
> I
> > avoid problems like the one I'm describing.  I absolutely love Maven
> > though
> > and am very very tempted to try out the newer stuff early :)
> >
> > On 8/8/07, Eric Redmond <er...@gmail.com> wrote:
> > >
> > > Ah, was not aware. Glad it's gotten fixed - I tend to run 2.1 anymore.
> > >
> > > On 8/8/07, Max Bowsher <ma...@ukf.net> wrote:
> > > >
> > > > Eric Redmond wrote:
> > > > > testResources files get copied to the testOutputDirectory. Using
> > > > surefire,
> > > > > the testOutputDirecotry files should take precedence.
> > > >
> > > > Actually, no. In Maven 2.0.7 and below, the main output directory
> > takes
> > > > precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.
> > > >
> > > > Compare the getTestClasspathElements method in:
> > > >
> > > >
> > > >
> > >
> >
> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> > > >
> > > >
> > >
> >
> http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> > > >
> > > > Max.
> > > >
> > >
> > >
> > >
> > > --
> > > Eric Redmond
> > > http://blog.propellors.net
> > >
> >
>

Re: Relationship of resources and testResources

Posted by Eric Redmond <er...@gmail.com>.
Well, 2.1 is a lot cooler than 2.0.x - however, I would tend to stay away
for now unless you want to get involved in the core - it's not THAT stable.
At least wait until the alpha release, which should be coming around in a
month or so.

-- 
Eric Redmond
http://blog.propellors.net

On 8/8/07, Ryan Moquin <fr...@gmail.com> wrote:
>
> Oh you run 2.1?  Do you build it from source?  I tend to try to stay away
> from non-stable builds unless there is a feature I really need, so that I
> avoid problems like the one I'm describing.  I absolutely love Maven
> though
> and am very very tempted to try out the newer stuff early :)
>
> On 8/8/07, Eric Redmond <er...@gmail.com> wrote:
> >
> > Ah, was not aware. Glad it's gotten fixed - I tend to run 2.1 anymore.
> >
> > On 8/8/07, Max Bowsher <ma...@ukf.net> wrote:
> > >
> > > Eric Redmond wrote:
> > > > testResources files get copied to the testOutputDirectory. Using
> > > surefire,
> > > > the testOutputDirecotry files should take precedence.
> > >
> > > Actually, no. In Maven 2.0.7 and below, the main output directory
> takes
> > > precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.
> > >
> > > Compare the getTestClasspathElements method in:
> > >
> > >
> > >
> >
> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> > >
> > >
> >
> http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> > >
> > > Max.
> > >
> >
> >
> >
> > --
> > Eric Redmond
> > http://blog.propellors.net
> >
>

Re: Relationship of resources and testResources

Posted by Ryan Moquin <fr...@gmail.com>.
Oh you run 2.1?  Do you build it from source?  I tend to try to stay away
from non-stable builds unless there is a feature I really need, so that I
avoid problems like the one I'm describing.  I absolutely love Maven though
and am very very tempted to try out the newer stuff early :)

On 8/8/07, Eric Redmond <er...@gmail.com> wrote:
>
> Ah, was not aware. Glad it's gotten fixed - I tend to run 2.1 anymore.
>
> On 8/8/07, Max Bowsher <ma...@ukf.net> wrote:
> >
> > Eric Redmond wrote:
> > > testResources files get copied to the testOutputDirectory. Using
> > surefire,
> > > the testOutputDirecotry files should take precedence.
> >
> > Actually, no. In Maven 2.0.7 and below, the main output directory takes
> > precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.
> >
> > Compare the getTestClasspathElements method in:
> >
> >
> >
> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> >
> >
> http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
> >
> > Max.
> >
>
>
>
> --
> Eric Redmond
> http://blog.propellors.net
>

Re: Relationship of resources and testResources

Posted by Eric Redmond <er...@gmail.com>.
Ah, was not aware. Glad it's gotten fixed - I tend to run 2.1 anymore.

On 8/8/07, Max Bowsher <ma...@ukf.net> wrote:
>
> Eric Redmond wrote:
> > testResources files get copied to the testOutputDirectory. Using
> surefire,
> > the testOutputDirecotry files should take precedence.
>
> Actually, no. In Maven 2.0.7 and below, the main output directory takes
> precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.
>
> Compare the getTestClasspathElements method in:
>
>
> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
>
> http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
>
> Max.
>



-- 
Eric Redmond
http://blog.propellors.net

Re: Relationship of resources and testResources

Posted by Max Bowsher <ma...@ukf.net>.
Eric Redmond wrote:
> testResources files get copied to the testOutputDirectory. Using surefire,
> the testOutputDirecotry files should take precedence.

Actually, no. In Maven 2.0.7 and below, the main output directory takes
precedence. In Maven 2.0.8-SNAPSHOT, this has been fixed.

Compare the getTestClasspathElements method in:

http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.7/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java

Max.


Re: Relationship of resources and testResources

Posted by Eric Redmond <er...@gmail.com>.
testResources files get copied to the testOutputDirectory. Using surefire,
the testOutputDirecotry files should take precedence.

-- 
Eric Redmond
http://blog.propellors.net

On 8/8/07, Ryan Moquin <fr...@gmail.com> wrote:
>
> If I have this in my pom:
>
> ....
> <build>
> <resources>
>       <resource>
>         <directory>src/main/resources</directory>
>       </resource>
>     </resources>
>     <testResources>
>       <testResource>
>         <directory>/src/test/resources</directory>
>       </testResource>
>     </testResources>
> </build>
> ....
>
> If I have a file such as hibernate.cfg.xml in both locations, but with
> different parameters... which one will take precedence during unit tests?
> From I can see, it seems like only the one in the src/main/resources takes
> effect.
>
> Do you have to do anything specific to make this work how I would expect?
>
> Thanks.
>