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

这是我对这个优秀小组的第一个问题,所以我希望我涵盖了所有的基础。

环境:

  • eclipse 靛蓝
  • m2e - Eclipse 的 Maven 集成 1.2.0.20120903-1050 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e
  • 用于 build-helper-maven-plugin 0.15.0.201207090124 org.sonatype.m2e.buildhelper.feature.feature.group Sonatype, Inc. 的 m2e 连接器
  • APT M2E 连接器 0.0.1.3 de.joe.m2e.apt.feature.feature.group null
  • Groovy-Eclipse 功能 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
  • Tycho 项目配置器 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 源目录被添加到 .classpath 但不是输出目录。

    然而,看着: thisthis使用 build-helper 应该可以解决问题。我尝试将 build-helper 引用放入项目 pom.xml 中,行为没有改变。我还尝试使用 maven-eclipse 插件来设置其他源文件夹,如 here 所述。和

    我们有四个使用 groovy 的子项目,当我们从 SVN 提取新代码时,我希望不必为 main 和 test 分别添加 groovy 文件夹和输出文件夹。看来M2E 的import maven 项目就是不能正常工作。 maven->updateProject 也没有。我错过了什么?

    作为一种解决方法,m2e 1.2 似乎没有像 m2e 1.0 喜欢的那样覆盖 .classpath 和 .project 文件,所以我总是可以手动配置 .classpath 和 .project 文件并将它们放入源代码管理中。

    请您参考如下方法:

    我在使用 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> 
    

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


    评论关闭
    IT干货网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!