我的项目是这样的:
我正在使用JDK1.6
Project (maven project)
Module_SERVER_SIDE
Module_TEST (it actaully extneds other Parent JUNIT test module)
src/java (put all existing java test source code here)
src/groovy (newly added , i put my ABCSpockTestSpec here)
我可以知道如何处理Java源代码的软件包名称问题吗? 原来的根文件夹是src,但是现在根文件夹变成src / java
是否应该像target / package / file.class一样将已编译的groovy .class / .groovy文件放入target / package / file.groovy?
如何在同一个MODULE_TEST中运行junit(java类)和spock(groovy类),现在的症状是.groovy文件未放入目标文件夹。
如何运行join groovy-java编译,我已阅读 http://docs.groovy-lang.org/latest/html/documentation/tools-groovyc.html#ThegroovycAntTask-JointCompilation,但没有运气。
我尝试了groovy-eclipse-compiler,但出现错误:
type groovy.lang.Closure cannot be resolved. It is indirectly referenced from required .class files
Class not found ABCSpockTestSpec
java.lang.ClassNotFoundException: com.package.ABCSpockTestSpec
这是我的pom.xml。谢谢。
<build>
<sourceDirectory>${basedir}/src </sourceDirectory>
<testSourceDirectory>${basedir}/src</testSourceDirectory>
<resources>
<resource>
<directory>${basedir}/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<!-- resource>
<directory>${basedir}/src</directory>
</resource-->
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Spec.groovy</include>
<include>**/*Spec.java</include>
<include>**/*.groovy</include>
</includes>
<!--
<excludes>
<excludes>**/somepackage/**</excludes>
</excludes>
-->
<argLine>${ArgLineValue}</argLine>
<testFailureIgnore>true</testFailureIgnore>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
</plugin>
</plugins>
/build>
reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
/reporting>
dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.13</version>
<scope>test</scope>
</dependency>
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
<!-- Enables mocking of classes (in addition to interfaces) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<!-- enables mocking of classes without default constructor (together with CGLIB) -->
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5</version>
</dependency>
/dependencies>
profiles>
<profile>
<id>emma</id>
<properties>
<backgroundStyle>3</backgroundStyle>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}/../ACON_PC_SHARED/resources</directory>
<includes>
<include>client.cst.xml</include>
<include>_aconShared.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skip.pc.module.tests}</skipTests>
</configuration>
</plugin>
<!-- start experiment by Glen 2018Mar05 Spock with Java -->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>
<directory>${basedir}/src/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
<testSources>
<testSource>
<directory>${basedir}/src/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
<!-- start experiment by Glen 2018Mar05 Spock with Java -->
<plugin>
<groupId> org.codehaus.groovy.maven </groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-3</version>
<extensions>true</extensions>
<executions>
<execution>
<goals><goal>testCompile</goal></goals>
<configuration>
<sources>
<fileset>
<directory>
${pom.basedir}/src/java
</directory>
<include>**/*.groovy</include>
</fileset>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- If run following plugin , then it cannot resolve the traditional JUnit, when I put them into
src/java and src/groovy separately -->
<!--<plugin>-->
<!--<groupId>org.codehaus.gmaven</groupId>-->
<!--<artifactId>groovy-maven-plugin</artifactId>-->
<!--</plugin>-->
<!-- If run following plugin , then it cannot resolve the traditional JUnit, when I put them intosrc/java and src/groovy separately -->
</plugins>
</build>
但是我遵循了
Running spock unit tests with Maven
Running groovy tests with Maven
还是没有运气。