Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346843 - create <sourceDirectory> during "convert to maven project"
Summary: create <sourceDirectory> during "convert to maven project"
Status: CLOSED DUPLICATE of bug 359340
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-23 05:54 EDT by Andre Dietisheim CLA
Modified: 2021-04-19 13:25 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andre Dietisheim CLA 2011-05-23 05:54:12 EDT
how to reproduce:

1) have an eclipse project with source folder in src (NOT src/main/java)
2) add a pom.xml to it that does NOT specify <sourceDirectory />
3) add maven nature to it
4) choose "Maven->Update Project Configuration"

Result:
Proj does not build any more. Digging into it you'll notice that maven removed the src-folder from the eclipse settings.

Afaik m2e would default the source-folder to src/main/java if this folder would exist at the time we told m2e to update the project configuration. I had an eclipse setting that pointed to src which was removed by m2e when updating the eclipse proj. IMHO m2e should default to src if maven could not find out about the src location (no setting in the pom, no src/main/java folder).

Workaround:
Add <sourceDirectory>src</sourceDirectory> to the build section of your pom.
Comment 1 Milos Kleint CLA 2011-05-23 06:36:50 EDT
<sourceDirectory>src</sourceDirectory> is not a workaround but a solution to a misconfiguration problem of yours. if you don't specify the <sourceDirectory> element, then it's value comes from the default root pom (as shipping with every maven binary).  The default value is src/main/java, if you want something else, you need to configure it. You can verify the content of your effective pom by running the mvn help:effective-pom command on your project to see what sourceDirectory you have specified.

as far as I can tell, your project should not even compile correctly when run with maven.

resolving as invalid, thought to be a user configuration problem, please reopen if you disagree.
Comment 2 Snjezana Peco CLA 2011-05-23 07:25:11 EDT
If you convert a non-maven Eclipse Java project, m2e would need to configure source folders correctly. m2e doesn't handle that correctly even in the case pom.xml doesn't exist (when skipping step #2 in comment #0).  

Try the following:

- create the default Eclipse Java project (src is the source folder)
- do not create pom.xml
- call Configure>Convert to Maven Project
m2e will remove the source folder.

This is a bug in m2e.
Comment 3 Milos Kleint CLA 2011-05-23 07:57:20 EDT
thanks for the details. the problem is therefore in Convert to Maven Project which shall set the source directory. However please note that if you had any jar libraries defined or any other configuration around that is not backed by a pom element in the new pom, you will loose those as well, or at least get a non-buildable maven buid.
Comment 4 Igor Fedorenko CLA 2011-08-01 02:58:56 EDT
ability to preserve custom .classpath entries is tracked separately as bug 353266
Comment 5 Scott Sosna CLA 2012-07-13 08:35:29 EDT
I have legacy projects that I converted to use Maven, but cannot use within Eclipse for the reasons discussed.  From command line or within IntelliJ, the projects build just fine, but because of m2e's handling of the source directory, it doesn't work correctly within Eclipse.

Please move this enhancement soon as its make it difficult for developers who want to use Maven (and yes, you could change the directory structure, but unfortunately that's not an option for all the wrong reasons).
Comment 6 Igor Fedorenko CLA 2012-07-13 08:56:19 EDT
m2e 1.1 creates <sourceDirectory> pom.xml element as part of "convert to maven" action. If this does not work for you, please open a new bugreport and provide small standalone example project and exact steps to reproduce the problem.

*** This bug has been marked as a duplicate of bug 359340 ***
Comment 7 Denis Roy CLA 2021-04-19 13:25:28 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/