2014-02-26 44 views
2

我要自動編譯和運行測試時,我使用mvn testmvn install如何使用Groovy的Maven插件

我用gmaven-plugin和它的作品的意願。

但是,當我使用groovy-maven-plugin,新版本的gmaven,它不起作用!

那麼如何配置?

這裏是我的pom.xml

<!-- gmaven-plugin --> 
<plugin> 
    <groupId>org.codehaus.gmaven</groupId> 
    <artifactId>gmaven-plugin</artifactId> 
    <version>1.5</version> 
    <configuration> 
     <providerSelection>2.0</providerSelection> 
     <source/> 
    </configuration> 
    <executions> 
     <execution> 
      <goals> 
       <goal>generateStubs</goal> 
       <goal>compile</goal> 
       <goal>generateTestStubs</goal> 
       <goal>testCompile</goal> 
      </goals> 
     </execution> 
    </executions> 
    <dependencies> 
     <dependency> 
      <groupId>org.codehaus.gmaven.runtime</groupId> 
      <artifactId>gmaven-runtime-2.0</artifactId> 
      <version>1.5</version> 
      <exclusions> 
       <exclusion> 
        <groupId>org.codehaus.groovy</groupId> 
        <artifactId>groovy-all</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.groovy</groupId> 
      <artifactId>groovy-all</artifactId> 
      <version>${groovy.version}</version> 
     </dependency> 
    </dependencies> 
</plugin> 

<!-- groovy-maven-plugin --> 
<plugin> 
    <groupId>org.codehaus.gmaven</groupId> 
    <artifactId>groovy-maven-plugin</artifactId> 
    <dependencies> 
    <dependency> 
     <groupId>org.codehaus.groovy</groupId> 
     <artifactId>groovy-all</artifactId> 
     <version>${groovy.version}</version> 
    </dependency> 
    </dependencies> 
</plugin> 
+0

當它不工作時會發生什麼?你有錯誤信息嗎? –

+0

我相信最初的groovy maven插件不再處於開發階段,通常Eclipse Groovy編譯器插件對於maven更受歡迎:http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven – cjstehno

+0

@drorb there是沒有錯誤的,但是當我運行'mvn test'時,新的插件將不會運行groovy測試。但是'1.5'版本會。 – Dozer

回答

5

除了Groovy Eclipse編譯器,還有一個新的GMavenPlus plugin可以支持聯合編譯。

關於測試,這裏是我的項目的POM示例,其中有GMavenPlus插件與Spock一起工作。

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin>    
      <plugin> 
       <groupId>org.codehaus.gmavenplus</groupId> 
       <artifactId>gmavenplus-plugin</artifactId> 
       <version>1.0</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>generateStubs</goal> 
          <goal>compile</goal> 
          <goal>testGenerateStubs</goal> 
          <goal>testCompile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <parallel>methods</parallel> 
        <threadCount>5</threadCount> 
        <includes> 
         <include>**/*Test.*</include> 
         <include>**/*Spec.*</include> 
        </includes> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.codehaus.groovy</groupId> 
      <artifactId>groovy-all</artifactId> 
      <version>2.2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.spockframework</groupId> 
      <artifactId>spock-core</artifactId> 
      <version>0.7-groovy-2.0</version> 
      <exclusions> 
       <exclusion> 
        <groupId>org.codehaus.groovy</groupId> 
        <artifactId>groovy-all</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>junit</groupId> 
        <artifactId>junit-dep</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
    </dependencies> 
相關問題