1

My project is like that:

I am using 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)

  1. May I know how to deal with the package name problem for java source code? the original root folder is src, but now the root folder become src/java

  2. Should the compiled groovy .class/.groovy file being put into target/package/file.groovy like target/package/file.class ?

  3. How can I run the junit (java class) and spock (groovy class) in my same MODULE_TEST ,now the syntom is that the .groovy file IS NOT Being put into target folder.

  4. How can I run join groovy-java compilation , I have read http://docs.groovy-lang.org/latest/html/documentation/tools-groovyc.html#ThegroovycAntTask-JointCompilation, but no luck.

  5. I tried groovy-eclipse-compiler, but errors: 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

here is my pom.xml .Thank you.

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

but I have followed the

Running spock unit tests with Maven

Running groovy tests with Maven

http://spock-framework.3207229.n2.nabble.com/How-to-add-Spock-tests-to-existing-Maven-build-with-Java-unit-tests-td7574013.html

still no luck at all.

user1638172
  • 103
  • 2
  • 2
  • 6
  • Why don't you use standard Maven folders, i.e. `src/main/java` for your application code, `src/test/java` and `src/test/groovy` for test code? Why not abide to the _convention over configuration_ principle if you are trying to do something you have no experience with? There are several other possible problems in your configuration, but I am in no mood to recreate your project from scratch, guessing what it might look like. If you upload an [MCVE](http://stackoverflow.com/help/mcve) to GitHub, I would take a loot at it and fix it for you if I have time. – kriegaex Jun 28 '18 at 13:18
  • @kriegaex, Thank you. However this is my company project. I cannot control the maven structure. [https://github.com/groovy/groovy-eclipse/issues/615] I created the issue in github – user1638172 Jun 28 '18 at 15:24
  • 1
    Do you always open bug tickets just because you don't understand how to use a software? And then also open the ticket in the wrong open source project? Also, it is a lame excuse to say that you cannot change the Maven structure of a project belonging to the very company you work for. Who else but someone from that company could change it? Obviously you could change it into using spock and thus breaking the build. So please think of a better excuse. – kriegaex Jun 29 '18 at 12:09

0 Answers0