Eclipse: generated-sources dir for Maven

4,905 views
Skip to first unread message

Martin Trummer

unread,
Nov 7, 2013, 9:16:38 AM11/7/13
to xtend...@googlegroups.com
how can I specify the Maven default directory for xtend generated java files in Eclipse?

When I enter generated-sources in the Directory input box of the xtend Compiler section in the project properties (as described here: http://www.eclipse.org/xtend/download.html#MavenSupport) then the files are generated in src/main/generated-sources, but should be here: target/generated-sources.
BTW: I also use the m2e plugin

Dennis Hübner

unread,
Nov 7, 2013, 11:21:55 AM11/7/13
to xtend...@googlegroups.com
It is interpreted as a relative path to the parent of the source folder, which includes the to-be-compiled Xtend file.
Sourcefolder relative, because in multi source folder projects you may end in a conflicting target folder.
I would suggest to keep xtend compiler setting as is and add src/main/generated-sources to maven sources.

<plugins>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>build-helper-maven-plugin</artifactId>

<executions>

<execution>

<id>add-source</id>

<phase>generate-sources</phase>

<goals>

<goal>add-source</goal>

</goals>

<configuration>

<sources>

<source>src/main/generated-sources</source>

</sources>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

Martin Trummer

unread,
Nov 7, 2013, 11:43:55 AM11/7/13
to xtend...@googlegroups.com
hi,

Sourcefolder relative, because in multi source folder projects you may end in a conflicting target folder.
what do you mean with "multi source folder projects"? do you mean a maven multi-module project?
I guess not, because each module would have it's own target folder and there's no conflict in that case.

I would suggest to keep xtend compiler setting as is and add src/main/generated-sources to maven sources.
I want to avoid this if possible. 
Whenever I did not stick to Maven-conventions in the past, I regretted that badly and I have the feeling that it will be no different in this case.
another thing I don't like about this is that I'd have to exclude parts of the src/main tree from my version control system.

anyway: I'd like to avoid this if possible, so I'd be grateful for a workaround that let's me stick to maven-conventions.
e.g. using '../../../target/generated-sources' (I've tried that - does not work)

 

Mit freundlichen Grüssen/Kind  regards,
 Martin Trummer
______________________________
DI (FH) Martin Trummer
Mobile: +43 676 700 47 81
skype:ds.martin.trummer
mailto:martin....@dewesoft.com
Attention! New mailaddress ends with .com (was .org before)

DEWESoft GmbH
Grazerstrasse 7
A-8062 Kumberg
Austria / Europe
Tel.: +43 3132 2252
Fax: +43 3132 2252
UID-Nr.: ATU 654 93414
FB-Nr.:  078/4236-21
www.dewesoft.com
______________________________

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and delete this e-mail.
Any unauthorized copying, disclosure or distribution of the material in this e-mail is prohibited.


--
You received this message because you are subscribed to a topic in the Google Groups "Xtend Programming Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xtend-lang/vGRX59En_5g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dennis Hübner

unread,
Nov 7, 2013, 1:05:19 PM11/7/13
to xtend...@googlegroups.com, martin....@dewesoft.com


On Thursday, November 7, 2013 5:43:55 PM UTC+1, Martin Trummer wrote:
hi,

Sourcefolder relative, because in multi source folder projects you may end in a conflicting target folder.
what do you mean with "multi source folder projects"? do you mean a maven multi-module project?
I guess not, because each module would have it's own target folder and there's no conflict in that case.
I mean if src/main/java contains foo.Class and src/test/java contains foo.ClassTest compilation would overlap. So in each case Java would be generated in target/generated-sources/foo/ folder.


I would suggest to keep xtend compiler setting as is and add src/main/generated-sources to maven sources.
I want to avoid this if possible. 
Ok I see.
 
Whenever I did not stick to Maven-conventions in the past, I regretted that badly and I have the feeling that it will be no different in this case.
another thing I don't like about this is that I'd have to exclude parts of the src/main tree from my version control system.

anyway: I'd like to avoid this if possible, so I'd be grateful for a workaround that let's me stick to maven-conventions.
e.g. using '../../../target/generated-sources' (I've tried that - does not work)

../../target/generated-sources works good for me. Which xtend version do you use? 

Martin Trummer

unread,
Nov 8, 2013, 5:00:40 AM11/8/13
to xtend...@googlegroups.com, martin....@dewesoft.com

thanks for the help - finally I got it working.
here's a summary - maybe it helps others.

Maven

defined variables

<xtendVersion>2.4.3</xtendVersion>
<xtendGenDirectory>target/generated-sources/xtend</xtendGenDirectory>

dependencies

                <dependency>
                        <groupId>org.eclipse.xtend</groupId>
                        <artifactId>org.eclipse.xtend.lib.gwt</artifactId>
                        <version>${xtendVersion}</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>org.eclipse.xtext</groupId>
                        <artifactId>org.eclipse.xtext.xbase.lib.gwt</artifactId>
                        <version>${xtendVersion}</version>
                        <scope>compile</scope>
                </dependency>

Xtend plugin to generate java files from the xtend files:

                        <plugin>
                                <groupId>org.eclipse.xtend</groupId>
                                <artifactId>xtend-maven-plugin</artifactId>
                                <version>${xtendVersion}</version>
                                <executions>
                                        <execution>
                                                <phase>generate-sources</phase>
                                                <goals>
                                                        <goal>compile</goal>
                                                </goals>
                                                <configuration>
                                                        <outputDirectory>${xtendGenDirectory}</outputDirectory>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>

tell the build-helper plugin to include the generated java files in the build process (the GWT compiler needs to find them):

                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>build-helper-maven-plugin</artifactId>
                                <version>1.8</version>
                                <executions>
                                        <execution>
                                                <id>add-source</id>
                                                <phase>generate-sources</phase>
                                                <goals>
                                                        <goal>add-source</goal>
                                                </goals>
                                                <configuration>
                                                        <sources>
                                                                <source>${xtendGenDirectory}</source>
                                                        </sources>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>

Eclipse

In the Project properties - section Xtend - Compiler - Outputfolder for generated Java files set the Directory to

../../target/generated-sources/xtend

Misc
  • I had to remove the strict flag for the GWT-compiler options.
    Otherwise there was an error when doing the GWT compilation - seemed to be related to guava sources.
  • the target directory must point to a folder where no other files or folders exists. e.g. usiung target/generated-sources instead of target/generated-sources/xtend does not work if there are also other artefacts generated into the same folder (e.g. the java-annotation processors will use target/generated-sources/annotations)
  • When you import the Maven project for the first time in eclipse you must do the Eclipse setup (see above) manually (m2e cannot do it automatically  - and since we need different folder-definitions in the pom.xml and in Eclipse this would not work anyway).

Martin Trummer

unread,
Nov 14, 2013, 11:44:04 AM11/14/13
to xtend...@googlegroups.com, martin....@dewesoft.com
just found out that the "execution section" from the xtend-maven-plugin is a bad idea (seem's I've copied it from a bad template project)- just remove it to avoid problems with JUnit test on the command line).

Ramon Rivas

unread,
Sep 6, 2014, 12:03:09 PM9/6/14
to xtend...@googlegroups.com, martin....@dewesoft.com
So you removed the configuration to generate sources in target?
Is there any way to make the xtend plugin generate sources inside target? I also feel more comfortable if xtend would put the sources inside target/generated-sources/xtend or at least target/xtend/sources/

thanks
Reply all
Reply to author
Forward
0 new messages