M2E does not add Groovy source to .classpath to import existing maven project

Using Eclipse Indigo to import an existing maven project, the resulting workspace project does not include src/main/groovy or src/test/groovy in the build path. I would also like to have an output directory for groovy code installed on target/test-classes .

This is my first question for this wonderful group, so I hope that I will use all the bases.

Environment:

  • Eclipse indigo
  • m2e - Maven Integration for Eclipse 1.2.0.20120903-1050 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e
  • m2e for build-helper-maven-plugin 0.15.0.201207090124 org.sonatype.m2e.buildhelper.feature.feature.group Sonatype, Inc.
  • APT M2E Connector 0.0.1.3 de.joe.m2e.apt.feature.feature.group null
  • Groovy -Eclipse Feature 2.5.2.xx-20110929-1800-e37 org.codehaus.groovy.eclipse.feature.feature.group Codehaus.org
  • Groovy -Eclipse M2E Integration 2.7.1.xx-20120921-2000-e37RELEASE org.codehaus.groovy.m2eclipse.feature.group Codehaus.org
  • Configurators Tycho Project 0.6.0.201207302152 org.sonatype.tycho.m2e.feature.feature.group Sonatype, Inc.

My pom.xml for the project:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.jha.yhs</groupId> <artifactId>fraud.server.parent</artifactId> <version>201203.8.0-SNAPSHOT</version> </parent> <artifactId>ach-wire</artifactId> <dependencies> <dependency> <groupId>com.jha.yhs</groupId> <artifactId>aspects</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.jha.yhs</groupId> <artifactId>database</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>r09</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.7.6</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>0.5-groovy-1.7</version> <scope>test</scope> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.155</version> </dependency> <dependency> <groupId>org.dbunit</groupId> <artifactId>dbunit</artifactId> <version>2.4.8</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.5.RELEASE</version> </dependency> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <scope>test</scope> <version>1.6.1</version> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.8.5</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> </plugin> </plugins> </build> </project> 

Now this pom.xml is a child (in a subdirectory) of another pom.xml that contains:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <compilerVersion>1.6</compilerVersion> <source>1.6</source> <target>1.6</target> <compilerArguments> <encoding>windows-1252</encoding> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/groovy</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.2</version> <configuration> <argLine>-Xmx1024m -XX:MaxPermSize=256m -XX:-HeapDumpOnOutOfMemoryError</argLine> <includes> <include>**/UnitTests.java</include> </includes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <dependencies> <dependency> <groupId>org.codehaus.gmaven.runtime</groupId> <artifactId>gmaven-runtime-1.7</artifactId> <version>1.3</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.7.6</version> </dependency> </dependencies> <configuration> <providerSelection>1.7</providerSelection> </configuration> <executions> <execution> <goals> <goal>generateStubs</goal> <goal>compile</goal> <goal>generateTestStubs</goal> <goal>testCompile</goal> </goals> </execution> </executions> </plugin> 

Note: I can add the groovy source folders using: - the GUI build path - by editing the .classpath file - run mvn eclipse: eclipse from the command line, and the original dir groovy is added to the .classpath, but not to the output directories.

However, looking at: this and this using build-helper should solve the problem. I tried to put the build-helper link in the pom.xml project without changing the behavior. I also tried using the maven-eclipse plugin to install additional source folders, as described here and

We have four of these subprojects that use groovy, and I would not want to add groovy folders and output folders for the main one and test for each of them whenever we get the new code from SVN. It seems that the M2E import maven project is just not working properly. Also maven-> updateProject doesn't matter. What am I missing from this?

As a job, it seems that m2e 1.2 does not overwrite .classpath and .project files such as m2e 1.0 that I like, so I can always manually configure the .classpath and .project files and put them in the original control.

+6
source share
1 answer

I am using Groovy in a webapp developing with Maven. But I use groovy-eclipse-compiler . First, I configure the Maven compiler plugin:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerId>groovy-eclipse-compiler</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>${groovy-eclipse-compiler.version}</version> </dependency> </dependencies> </plugin> 

Then I configure the source directories:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/groovy</source> </sources> </configuration> </execution> </executions> </plugin> 

After that, I can use Groovy with Eclipse + m2e (in fact, I use the Springsource Tool Suite with the Groovy plugin). I have Groovy syntax and autocomplete (far from perfect), I can also use Groovy classes from Java and vice versa.

0
source

Source: https://habr.com/ru/post/927206/


All Articles