copying of resources

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

copying of resources

Levi Hoogenberg
Hello,

I noticed that the Resources task copies resource files to the classes/test-classes directories. What's the reasoning behind this? I never had the need to do this in my Ant projects (neither for testing, packaging, nor running an exploded web application).

The reason I'm asking is that after running all of my tests from the command line, the copied resources take precedence over the original resource files in Eclipse (I'm configuring src/main/resources as class folders, not as source folders) and the only way for me to get Eclipse to pick up my changes is to clean all of my projects. I'd rather avoid this :)

Another disadvantage is that copying resources starts take a long time as soon as you're having a lot of them or when they are large, although that may not be the best argument given today's computers :)

Regards,
  Levi
Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

hans_d
Administrator
Hi Levi,

On Oct 3, 2008, at 4:11 PM, Levi Hoogenberg wrote:

> Hello,
>
> I noticed that the Resources task copies resource files to the  
> classes/test-classes directories. What's the reasoning behind this?  
> I never had the need to do this in my Ant projects (neither for  
> testing, packaging, nor running an exploded web application).

The JavaPlugin add two task instances of type Resource. One has the  
name 'resources' and copies files from src/main/resources to build/
classes. The other has the name 'testResources' and copies files from  
src/main/testResources to build/test-classes. One use case for the  
latter is that you need resource files in your tests which should not  
be part of the production code. The other use case is that if you can  
overwrite resource of your production code. When running the tests,  
build/test-classes has precedence over build/classes.

I have done it like this also in my Ant builds. Maven also works like  
this. See below for the reasons.

>
> The reason I'm asking is that after running all of my tests from  
> the command line, the copied resources take precedence over the  
> original resource files in Eclipse (I'm configuring src/main/
> resources as class folders, not as source folders) and the only way  
> for me to get Eclipse to pick up my changes is to clean all of my  
> projects. I'd rather avoid this :)

As I understand it the following happens in your case. Your Eclipse  
classpath contains src/main/resources and build/classes. In your set  
up build/classes has a higher precedence than src/main/resources.  
Gradle copies the resources into build/classes as part of the build  
and any changes you do to src/main/resources don't have any effect.

Defining src/main/resources as a source folder would solve the  
problem? I guess you don't like this for performance reasons as you  
have mentioned below? Another solution would be to change the  
classpath order of the classpath folders.

How is the build/test-classes stuff you mentioned above related to this?

> Another disadvantage is that copying resources starts take a long  
> time as soon as you're having a lot of them or when they are large,  
> although that may not be the best argument given today's computers :)

A not uncommon use case is that you don't use the src/main/resources  
folder as it is, but apply transformation to it. For example Gradle  
supports the use of filters. You can substitute placeholders in the  
source-resource files with values defined at build time (e.g. version  
number).

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

Levi Hoogenberg
Hello Hans,

thank you very much for your detailed answer.

As I understand it the following happens in your case. Your Eclipse classpath contains src/main/resources and build/classes. In your set up build/classes has a higher precedence than src/main/resources. Gradle copies the resources into build/classes as part of the build and any changes you do to src/main/resources don't have any effect.

That's correct.
 
Defining src/main/resources as a source folder would solve the problem? I guess you don't like this for performance reasons as you have mentioned below? Another solution would be to change the classpath order of the classpath folders.

Using src/main/resources as source folder would solve the issue, but I don't like that (not just for performance reasons, but in Eclipse a class folder is just conceptually the better option, IMO). Changing the order helps as well (thought I tried that): classpath entries that are defined last have the highest priority. I'll add this to the JIRA issue I created. 

How is the build/test-classes stuff you mentioned above related to this?

That's the exact same issue.

A not uncommon use case is that you don't use the src/main/resources folder as it is, but apply transformation to it. For example Gradle supports the use of filters. You can substitute placeholders in the source-resource files with values defined at build time (e.g. version number).

Ah. I've never had this use case, but I see why copying is necessary in this case.

I don't run manual builds that often, but do most things [testing, running Jetty, usw ;)] from within Eclipse. So it would be great if that could work with just a 'gradle eclipse' command.

Regards,
  Levi
Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

hans_d
Administrator

On Oct 6, 2008, at 11:57 AM, Levi Hoogenberg wrote:

<snip>

>
> Defining src/main/resources as a source folder would solve the  
> problem? I guess you don't like this for performance reasons as you  
> have mentioned below? Another solution would be to change the  
> classpath order of the classpath folders.
>
> Using src/main/resources as source folder would solve the issue,  
> but I don't like that (not just for performance reasons, but in  
> Eclipse a class folder is just conceptually the better option,  
> IMO). Changing the order helps as well (thought I tried that):  
> classpath entries that are defined last have the highest priority.  
> I'll add this to the JIRA issue I created.

I definitely see your point. I would like to hear what other Eclipse  
users think about this. The Maven plugin for creating Eclipse files  
creates source folders for resources folders. I don't have a clear  
opinion yet. Basically the same discussion is valid for IntelliJ  
(Unfortunately we don't have an IntelliJ plugin yet).

<snip>

> I don't run manual builds that often, but do most things [testing,  
> running Jetty, usw ;)] from within Eclipse. So it would be great if  
> that could work with just a 'gradle eclipse' command.
>
> Regards,
>   Levi

Just to be sure. As I understand it 'gradle eclipse' works in your  
case, but you don't want resources to be a src folder, right?

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

Levi Hoogenberg
On Mon, Oct 6, 2008 at 12:28 PM, Hans Dockter <[hidden email]> wrote:
I definitely see your point. I would like to hear what other Eclipse users think about this. The Maven plugin for creating Eclipse files creates source folders for resources folders. I don't have a clear opinion yet. Basically the same discussion is valid for IntelliJ (Unfortunately we don't have an IntelliJ plugin yet).

I'm interested in what others think as well - if I'm the only one who likes the class folder functionality, maybe I'm the one who should change his process.
 
Just to be sure. As I understand it 'gradle eclipse' works in your case, but you don't want resources to be a src folder, right?

That's right (see http://jira.codehaus.org/browse/GRADLE-253). Although what you said about modified resources got me thinking - how do you (or other Eclipse users who might read this) handle the filtering case you described when you're running tests inside Eclipse?
Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

hans_d
Administrator

On Oct 6, 2008, at 1:16 PM, Levi Hoogenberg wrote:

> On Mon, Oct 6, 2008 at 12:28 PM, Hans Dockter <[hidden email]>  
> wrote:
> I definitely see your point. I would like to hear what other  
> Eclipse users think about this. The Maven plugin for creating  
> Eclipse files creates source folders for resources folders. I don't  
> have a clear opinion yet. Basically the same discussion is valid  
> for IntelliJ (Unfortunately we don't have an IntelliJ plugin yet).
>
> I'm interested in what others think as well - if I'm the only one  
> who likes the class folder functionality, maybe I'm the one who  
> should change his process.
>
> Just to be sure. As I understand it 'gradle eclipse' works in your  
> case, but you don't want resources to be a src folder, right?
>
> That's right (see http://jira.codehaus.org/browse/GRADLE-253).  
> Although what you said about modified resources got me thinking -  
> how do you (or other Eclipse users who might read this) handle the  
> filtering case you described when you're running tests inside Eclipse?

In our special case we have the following situation. We automatically  
generate a properties file as part of the build and put it in the  
build/classes folder. This is used by the production code. We have a  
dummy version of this property file in the src/test/resources folder.  
Therefore when the unit tests are running this resource exists and we  
can check against defined values. When we run Gradle or the  
integration tests from our IDE the dummy version is also used. In our  
case this is fine (as it contains only versioning information). In  
other more complicated cases I guess you have to customize the  
Eclipse builder. But I never had to deal with such a situation.

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

helmut.denk
In reply to this post by Levi Hoogenberg
hi,

levi_h wrote
how do you (or other Eclipse users who might read this) handle the filtering case you described
when you're running tests inside Eclipse?
i do not  have /src/main/resources or /src/test/resources
registered as eclipse 'Source-Folders'.

if something changes in the resources i run gradle before
i run unit-tests inside of eclipse.

i dont see another solution esp. if you use
transformed or filtered resources.

have a nice day !
Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

helmut.denk
to automate this, a eclipse-plugin could
hook into eclipse and do a 'gradle resources'
when appropriate.

gradle should have some kind of embedded-mode
to save startup-time then ... i think i have read
about embedded-mode somewhere in the docs but
don't remember where it was.

Helmut Denk wrote
hi,

levi_h wrote
how do you (or other Eclipse users who might read this) handle the filtering case you described
when you're running tests inside Eclipse?
i do not  have /src/main/resources or /src/test/resources
registered as eclipse 'Source-Folders'.

if something changes in the resources i run gradle before
i run unit-tests inside of eclipse.

i dont see another solution esp. if you use
transformed or filtered resources.

have a nice day !
Reply | Threaded
Open this post in threaded view
|

Re: copying of resources

hans_d
Administrator
Hi Helmut,

On Oct 7, 2008, at 10:09 AM, Helmut Denk wrote:

>
> to automate this, a eclipse-plugin could
> hook into eclipse and do a 'gradle resources'
> when appropriate.
>
> gradle should have some kind of embedded-mode
> to save startup-time then ... i think i have read
> about embedded-mode somewhere in the docs but
> don't remember where it was.
>

You can use Gradle embedded. An UI usage is a perfect use case for  
this. And as you have said, it would improve the startup time. In  
fact we plan to ship an UI runner with Gradle for this reason and for  
more dynamic progress reporting.

For anyone reading this: We are looking for volunteers, you might  
think its could be fun to use for example the Groovy Swing Builder to  
create a really useful app :)

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

    http://xircles.codehaus.org/manage_email