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.

Roland Tepp
  • 8,301
  • 11
  • 55
  • 73
  • 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. – Cephalopod Feb 11 '13 at 11:06
  • yes, but the project IS java project and it HAS a source folder. There is nothing optional about it. – Roland Tepp Feb 11 '13 at 12:09
  • 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. – Cephalopod Feb 11 '13 at 12:24
  • so the question becomes - how do I tell Maven that this folder is not optional? – Roland Tepp Feb 11 '13 at 12:30
  • If this is even possible... You could try to explicitly set [´build/sourcedirectory´](http://maven.apache.org/pom.html), 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](http://netbeans.org/) that does not need half-matured plugins to build maven projects ;) – Cephalopod Feb 11 '13 at 13:53

1 Answers1

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).

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • 1
    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. – Roland Tepp Feb 13 '13 at 07:40
  • 1
    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. – Andrew Eisenberg Feb 13 '13 at 17:49