Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived resources are not copied to target/classes #1710

Open
OLibutzki opened this issue Mar 11, 2024 · 7 comments
Open

Derived resources are not copied to target/classes #1710

OLibutzki opened this issue Mar 11, 2024 · 7 comments

Comments

@OLibutzki
Copy link

I have a Maven project which contains multiple resources folders. One of the resources folders is target/generated-resources. As target is a derived folder all its containing resources are marked as derived as well.

target/generated-resources contains files which are generated by some external process.

Changes in the derived folder target/generated-resources don't trigger a Maven's resources plugin and therefore the resources are not copied to target/classes.

At least from my point of view this behaviour is unexpected as I want all the resources in a Maven resource folder to be copied to target/classes.

I set up a little reproducer: https://github.com/OLibutzki/m2e-copy-resources

There are three resource folder: src/main/resources, src/main/resources2 and target/generated-resources
Changes in src/main/resources and src/main/resources2 trigger the Maven copy resource actionas one can see in the Maven console:

11.03.24, 11:16:57 MEZ: [INFO] Copying 1 resource from src\main\resources to target\classes
11.03.24, 11:16:57 MEZ: [INFO] Copying 0 resource from src\main\resources2 to target\classes
11.03.24, 11:16:57 MEZ: [INFO] Copying 0 resource from target\generated-resources to target\classes
11.03.24, 11:16:57 MEZ: [INFO] skip non existing resourceDirectory D:\Projekte\ide\pls-cm-master\ws\m2e-copy-resources\src\test\resources

Whenever I change something in target/generated-resources there is no output in the Maven console.

However, when I change a resource in src\main\resources again, my change in target/generated-resources has been taken into consideration and is copied:

11.03.24, 11:19:46 MEZ: [INFO] Copying 1 resource from src\main\resources to target\classes
11.03.24, 11:19:46 MEZ: [INFO] Copying 0 resource from src\main\resources2 to target\classes
11.03.24, 11:19:46 MEZ: [INFO] Copying 1 resource from target\generated-resources to target\classes
11.03.24, 11:19:46 MEZ: [INFO] skip non existing resourceDirectory D:\Projekte\ide\pls-cm-master\ws\m2e-copy-resources\src\test\resources
@laeubi
Copy link
Member

laeubi commented Mar 11, 2024

Why does your "external process" does not copy them to target/classes as well? In general if something happens "outside" maven /m2e there is no guarantee that anything will happen at all.

@OLibutzki
Copy link
Author

@laeubi , the external process controls the lifecycle of the directory... so it's also capable of cleaning the whole folder... that's not an action it should perform on target/classes as there are also files from other sources.

@OLibutzki
Copy link
Author

@laeubi I am quite sure that this behaviour has changed in the last couple of months. Is it possible that #1275 is responsible for this change?

So you would say that not triggering Maven's resources plugin is the intended behaviour?

As a workaround, we could generate the resources to another folder which is not a target subfolder.

@laeubi
Copy link
Member

laeubi commented Mar 11, 2024

The behavior is that any change in the sources triggers a build (what probably trigger copy of resources). The target folder is the property of the build, so everything there is assumed to be a result of a build triggered, if you now change something in that folder from outside this is (no longer) detected.
I think having an external process placing files inside a folder of a maven build is quite unusual, how does it work in a regular build?

@OLibutzki
Copy link
Author

It's a frontend build which is triggerd by the frontend-maven-plugin in the generate-resources phase.

While developing there is a watcher which automcially builds the frontend whenever a source file is changed. The frontend tooling puts its stuff into target/generated-frontend.

@laeubi
Copy link
Member

laeubi commented Mar 11, 2024

It's a frontend build which is triggerd by the frontend-maven-plugin in the generate-resources phase.

Okay so actually I would expect in the dev build that this is also executed as part of build? Or is the execution supressed?

While developing there is a watcher which automcially builds the frontend whenever a source file is changed.

Could this watcher maybe trigger a build of the project then?

@OLibutzki
Copy link
Author

OLibutzki commented Mar 11, 2024

Okay so actually I would expect in the dev build that this is also executed as part of build? Or is the execution supressed?

It is suppressed because using the incremental build feature of m2e we have not been able to perform an incremental frontend build. We would have to trigger a full frontend build which takes too much time. That's the reason why we decided that Eclipse should just get the generated resources and its only responsibility is to copy them to target/classes.

Could this watcher maybe trigger a build of the project then?

To be honest, I don't have a clue how. My expectation was that the chnaged resources trigger the build automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants