M2E在导入现有maven项目时没有将Groovy源添加到.classpath

时间:2012-10-08 19:12:27

标签: eclipse maven groovy m2e

使用Eclipse Indigo导入现有的maven项目,生成的工作区项目在构建路径中不包含src/main/groovysrc/test/groovy。我还希望将groovy代码的输出目录设置为target/test-classes

这是我对这个优秀团队的第一个问题,所以我希望我能涵盖所有基础。

环境:

  • Eclipse Indigo
  • m2e - Eclipse的Maven Integration 1.2.0.20120903-1050 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e
  • 用于build-helper-maven-plugin的m2e连接器0.15.0.201207090124 org.sonatype.m2e.buildhelper.feature.feature.group Sonatype,Inc。
  • APT M2E Con​​nector 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集成2.7.1.xx-20120921-2000-e37RELEASE org.codehaus.groovy.m2eclipse.feature.group Codehaus.org
  • 第谷项目配置器0.6.0.201207302152 org.sonatype.tycho.m2e.feature.feature.group Sonatype,Inc。

我的项目的pom.xml是:

<?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>

现在这个pom.xml是另一个pom.xml的子目录(在子目录中),其中包含:

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

请注意,我可以使用以下命令添加groovy源文件夹:   - GUI的构建路径   - 通过编辑.classpath文件   - 运行mvn eclipse:从命令行执行eclipse,并将groovy源dir添加到.classpath但不添加到输出目录。

但是,使用build-helper查看:thisthis可以解决问题。我已经尝试将build-helper引用放入项目pom.xml中,但行为没有变化。我也尝试使用maven-eclipse插件来设置here

所述的其他源文件夹

我们有四个使用groovy的子项目,我希望无需每次从SVN提取新代码时都为main添加groovy文件夹和输出文件夹并测试每个文件夹。 似乎M2E的导入maven项目无法正常工作。 maven-&gt; updateProject也没有。我错过了什么?

作为一种解决方法,似乎m2e 1.2不会覆盖m2e 1.0喜欢的.classpath和.project文件,因此我总是可以手动配置.classpath和.project文件并将它们放入源代码控制中。

1 个答案:

答案 0 :(得分:0)

我在使用Maven进行webapp开发时使用Groovy。但我正在使用groovy-eclipse-compiler。首先,我配置Maven编译器插件:

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

然后,我配置源目录:

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

之后,我可以在Eclipse + m2e中使用Groovy(实际上,我使用带有Groovy插件的Springsource Tool Suite)。我有Groovy语法和自动完成(远非理想),我也可以使用Java中的Groovy类,反之亦然。