why does m2e plugin for eclipse insert optional attribute to src and what does it do
Asked Answered
E

1

8

I started noticing these attributes in my .classpath file after running Maven -> Update Project... tool with Update project configuration from pom.xml option checked:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
         </attributes>
    </classpathentry>
    ...
</classpathentry>

The attribute that made me raise my eyebrows the most was this: <attribute name="optional" value="true"/>.

What does it do? It looks mighty suspicious as I find nothing optional about my java source files in a project.

Elate answered 11/2, 2013 at 10:58 Comment(5)
I don't know much about the inner workings of eclipse, but you can have Maven projects without a src folder (e.g, parent and aggregation projects). Without the optional, the classpath configuration above would break for such projects.Orose
yes, but the project IS java project and it HAS a source folder. There is nothing optional about it.Elate
Depends on your definition of "optional". Without "src", it'll still be a valid maven project. And nowhere in the pom did you specify that the folder is not optional (I suspect); so maybe you require the folder, but it is optional for all tools involved.Orose
so the question becomes - how do I tell Maven that this folder is not optional?Elate
If this is even possible... You could try to explicitly set ´build/sourcedirectory´, but it might as well be that m2e sets this attribute by default. Maybe you should ask on their mailing list what you could do ... or ... use an IDE that does not need half-matured plugins to build maven projects ;)Orose
R
2

This is added because the src folder is an optional folder for maven. The project should not complain if src is missing. (Actually by default, this should be src/main/java and src/test/java). This means that adding or removing src as a source file should not require updating your maven configuration.

This attribute doesn't need to be there in your case, but it makes it plain that maven doesn't care if the source folder exists as long as everything can be compiled (so Eclipse shouldn't care either).

Renz answered 12/2, 2013 at 23:20 Comment(2)
This seems kind of superfluous. In case I have the source folder, it is clearly needed for this particular project. In case I do not, well, it is not needed. Not that I feel a need to argue with m2e/Maven on this. It just strikes me as unnecessary as I see no use case for such an attribute.Elate
Whether or not you think it is superfluous, that is how m2e is implemented. :-) I'm guessing that the reason for this decision is that if your project initially didn't have an src/main/java folder and one was added, this would be picked up by maven and controlled by m2e.Renz

© 2022 - 2024 — McMap. All rights reserved.