# Create a task where src/test/groovy be able to access src/test/java

**URL:** <https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043>\
**Category:** Help/Discuss\
**Created:** [January 30, 2016, 2:57pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043 "2016-01-30T14:57:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [January 30, 2016, 2:57pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/1 "2016-01-30T14:57:43Z")

</div>

Hello

I am working with Gradle and about testing with Spock Framework (Groovy)

I have in my project:

- src/main/java
- src/main/resources
- src/test/java
- src/test/resources
- src/test/groovy (For Spock)

I have no problems.

In `src/test/groovy` I have my Test classes written on Groovy, all compile and pass. For some test classes exist or use some UtilsTest classes located in other package.

If I _move_ the _util_ package from `src/test/groovy` to `src/test/java` and of course change the file from `.groovy` to `.java`. I can’t compile anymore. Practically `src/test/groovy` _can’t_ access `src/test/java` about compilation.

But If I move the _util_ package from `src/test/java` to `src/test/groovy` (keeping the _.java_ extension) all work again.

Through Gradle, is possible create a task based on `Test` where `src/test/groovy` _can_ access `src/test/java`?

I don’t want have in `src/test/groovy` a _.java_ file, they should be located on `src/test/java`.

Remember they are utils classes only created for testing. So move them in to `src/main/java` is not an option.

Thanks

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [February 2, 2016, 4:47am UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/2 "2016-02-02T04:47:00Z")

</div>

My guess is the class you moved to _src/test/java_ depends on something in _src/test/groovy_. In this case Groovy code can access Java code but not the other way around. The exception is if you put both Java _and_ Groovy code in _src/test/groovy_ then we automatically utilize [joint compilation](http://www.groovy-lang.org/groovyc.html#section-jointcompilation).

---

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [February 12, 2016, 12:51pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/3 "2016-02-12T12:51:00Z")

</div>

Thanks by the reply Mark

Sorry by my delay.

> My guess is the class you moved to src/test/java depends on something in src/test/groovy

No, really sure that Groovy code depends on Java.

What I need is have test code on _src/test/java_ and _src/test/groovy_

It assuming the following:

- In _src/test/java_ I have Test code based in Java which would use some Utils Test classes written in Java
- In _src/test/groovy_ have Test code based in Groovy which would **use the same Utils Test classes written in Java** and located on _src/test/java_

Test Java code does not use Spock and Groovy Code does use Spock.

What extra configuration in the IDE (STS/Eclipse) or in Gradle I need to let any code from _src/test/groovy_ see any code from _src/test/java_ and viceversa.

Thanks

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [February 15, 2016, 4:22am UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/4 "2016-02-15T04:22:23Z")

</div>

> [@dr\_pompeii](#):
>
> What extra configuration in the IDE (STS/Eclipse) or in Gradle I need to let any code from src/test/groovy see any code from src/test/java and viceversa.

Is the problem you’re having only in the IDE? Are you able to build with Gradle via the command line? What you are describing should work just fine however I’m not certain how STS handles this.

---

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [February 15, 2016, 12:53pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/5 "2016-02-15T12:53:25Z")

</div>

Hi Mark

> [@mark\_vieira](#):
>
> Is the problem you’re having only in the IDE? Are you able to build with Gradle via the command line?

it fails for both scenarios, with IDE and command line.

I am with the impression to do something extra about configuration.

If you have suggestions… let me know…

Thanks!

---

<div class="post-metadata">

**Author:** ![pledbrook](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pledbrook/32/1101_2.png) [@pledbrook](https://discuss.gradle.org/u/pledbrook)\
**Post date:** [February 16, 2016, 9:38am UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/6 "2016-02-16T09:38:36Z")

</div>

What does the compilation error say when using the Gradle build?

---

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [February 16, 2016, 2:21pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/7 "2016-02-16T14:21:20Z")

</div>

Hi pledbrook

Check the following (through terminal):

```gradle
gradle test
TOMCAT_HOME: /Users/manueljordan/whiteroom/apache/tomcat/8.0.26
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava
/Users/manueljordan/whiteroom/sts-workspace-laboratorio/Laboratory/web/web-25/src/test/java/com/manuel/jordan/rest/persona/support/PersonaRestControllerSupportTest.java:24: error: cannot find symbol
	public static final String ROOT_URI_XMLEXTENSION = PersonaRestControllerSupport.ROOT_URI + ControllerSupportTest.XML_EXTENSION;
	                                                                                           ^
  symbol: variable ControllerSupportTest
  location: class PersonaRestControllerSupportTest
/Users/manueljordan/whiteroom/sts-workspace-laboratorio/Laboratory/web/web-25/src/test/java/com/manuel/jordan/rest/persona/support/PersonaRestControllerSupportTest.java:29: error: cannot find symbol
	public static final String ROOT_URI_JSONEXTENSION = PersonaRestControllerSupport.ROOT_URI + ControllerSupportTest.JSON_EXTENSION;
	                                                                                            ^
  symbol: variable ControllerSupportTest
  location: class PersonaRestControllerSupportTest

....
more and more

```

In this case Java depends in other .java classes located on `src/test/groovy` but it can’t be reach it from `src/test/java`.

It happens in vice versa if I move all the .java classes from `src/test/groovy` to `src/test/java`. Therefore the .groovy files located on `src/test/groovy` can’t reach the .java classes from `src/test/java`.

I am with the impression something is missing, some extra configuration in the IDE or through Gradle.

Let me know if you need more data (the same error stack trace shown above appears in the IDE too, of course in the Console view.)

Thanks

---

<div class="post-metadata">

**Author:** ![pledbrook](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pledbrook/32/1101_2.png) [@pledbrook](https://discuss.gradle.org/u/pledbrook)\
**Post date:** [February 17, 2016, 8:15am UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/8 "2016-02-17T08:15:05Z")

</div>

This is expected. Code in _src/test/java_ can’t see the code in _src/test/groovy_, because the Java compilation happens first. However, your original report said that code in _src/test/groovy_ couldn’t see the classes from _src/test/java_, which shouldn’t be the case.

---

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [February 17, 2016, 1:28pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/9 "2016-02-17T13:28:21Z")

</div>

Hi pled brook

> This is expected. Code in src/test/java can’t see the code in src/test/groovy, because the Java compilation happens first.

Ok, I see it has sense. And it is reflected about the order of execution of the tasks that the console/terminals show when I execute the `gradle test` command

> However, your original report said that code in src/test/groovy couldn’t see the classes from src/test/java, which shouldn’t be the case

In that situation, I moved all the packages with any _.java_ file to `src/test/java`. Totally sure through the View Explorer that I can see in `src/test/groovy` only packages containing _.groovy_ files.

Now I get:

```gradle
com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest findOneById accept json xml FAILED
    groovy.lang.MissingPropertyException at PersonaFindOneRestControllerTest.groovy:302

com.manuel.jordan.rest.persona.PersonaSaveOneRestControllerTest initializationError FAILED
    java.lang.NullPointerException

com.manuel.jordan.rest.persona.PersonaUpdateOneRestControllerTest initializationError FAILED
    java.lang.NullPointerException

97 tests completed, 97 failed
:test FAILED

```

Where that 302 line is

```gradle
uriRequestReport << [ControllerSupportTest.findOneByIdTemplateFactory(PersonaRestControllerSupport.URI_ID, ControllerSupportTest.ID_URI_VALUE)]

```

That classes are located on `src/test/java`

If I use the `grade test --info` I get

```gradle
com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest > findOneById accept json xml FAILED
    groovy.lang.MissingPropertyException: No such property: ControllerSupportTest for class: com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest
        at com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest.findOneById accept json xml(PersonaFindOneRestControllerTest.groovy:302)

com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest STANDARD_ERROR
    Feb 17, 2016 8:21:48 AM org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
    INFO: com.athaydes.spockframework.report.internal.HtmlReportCreator failed to create report for com.manuel.jordan.rest.persona.PersonaFindOneRestControllerTest
    java.lang.ArrayIndexOutOfBoundsException: 0
    	at org.spockframework.runtime.extension.builtin.UnrollNameProvider.evaluateExpression(UnrollNameProvider.java:74)
    	at org.spockframework.runtime.extension.builtin.UnrollNameProvider.nameFor(UnrollNameProvider.java:53)
    	at org.spockframework.runtime.extension.builtin.UnrollNameProvider.getName(UnrollNameProvider.java:44)
    	at org.spockframework.runtime.extension.builtin.UnrollNameProvider.getName(UnrollNameProvider.java:30)

```

and more

```gradle
com.manuel.jordan.rest.persona.PersonaUpdateOneRestControllerTest > initializationError FAILED
    java.lang.NullPointerException: Cannot get property 'featureRuns' on null object

```

Some ideas?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pledbrook](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pledbrook/32/1101_2.png) [@pledbrook](https://discuss.gradle.org/u/pledbrook)\
**Post date:** [February 17, 2016, 2:49pm UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/10 "2016-02-17T14:49:38Z")

</div>

Did you import `ControllerSupportTest`? That would explain the `MissingPropertyException`. I would expect a different error if the class was imported but not found.

Also, note that these are runtime issues, not compilation ones.

---

<div class="post-metadata">

**Author:** ![dr\_pompeii](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dr\_pompeii](https://discuss.gradle.org/u/dr_pompeii)\
**Post date:** [February 18, 2016, 2:20am UTC](https://discuss.gradle.org/t/create-a-task-where-src-test-groovy-be-able-to-access-src-test-java/14043/11 "2016-02-18T02:20:16Z")

</div>

Hi

> Did you import ControllerSupportTest? That would explain the MissingPropertyException

Yes, I did check that a lot of times… totally sure the correct packages have been imported

> Also, note that these are runtime issues, not compilation ones.

I think that is a secondary consequence from the “missing” import packages.

Well… now all is working…

For one .groovy file (among others)

Just how playing from:

```gradle
import com.manuel.jordan.domain.*
import com.manuel.jordan.context.*
import com.manuel.jordan.rest.support.*
import com.manuel.jordan.domain.factory.*
import com.manuel.jordan.controller.support.*
import com.manuel.jordan.rest.persona.support.*

```

to

```gradle
import com.manuel.jordan.domain.*;
import com.manuel.jordan.context.*;
import com.manuel.jordan.rest.support.*;
import com.manuel.jordan.domain.factory.*;
import com.manuel.jordan.controller.support.*;
import com.manuel.jordan.rest.persona.support.*;

```

How you can see, I just added the `;`

and all work.

Wondered … some idea?

Even more interesting, I executed `gradle clean` (how I did do many times before) and I’ve removed the `;` from the import declarations (assuming that the same exceptions should appear again…) and all still work fine.

I am confused…

Thanks to both by your support.
