# Test task sources

**URL:** <https://discuss.gradle.org/t/test-task-sources/41192>\
**Category:** Help/Discuss\
**Created:** [October 13, 2021, 2:16pm UTC](https://discuss.gradle.org/t/test-task-sources/41192 "2021-10-13T14:16:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [October 13, 2021, 2:16pm UTC](https://discuss.gradle.org/t/test-task-sources/41192/1 "2021-10-13T14:16:54Z")

</div>

```gradle
test {
    classpath += files( "${buildDir}/libs/${project.transformedJarName}" )
    classpath += files( project.transformedTestDir )
    testClassesDirs += files( project.transformedTestDir )

    ...
}

```

The gist is that we transform the jars from another local project, including its test jar. I try to then run tests using that transformed test jar. However, I get:

```gradle
> Task :hibernate-core-jakarta:test NO-SOURCE

```

What are the sources for the test task? Is it literally looking for the test sources as in .java files? Why would the test task need access to the sources? And if so (odd, but ok), how do you tell it about the source files? Is via SourceSet the only option?

---

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [October 14, 2021, 4:04pm UTC](https://discuss.gradle.org/t/test-task-sources/41192/2 "2021-10-14T16:04:48Z")

</div>

And actually, even “faking” the test sources in SourceSet does not work. E.g.

```gradle
// `hibernate-core/src/test/java` exists and contains valid Java source files

// no idea why (and noone seems to know why - https://discuss.gradle.org/t/test-task-sources/41192)
// but Gradle's Test task needs access to the test source files. makes no sense... :shrug:
// "fake it" and just use hibernate-core's test sources
sourceSets.test.java.srcDir project( ':hibernate-core' ).file( 'src/test/java' )

```

still gives:

```gradle
...
> Task :hibernate-core-jakarta:test NO-SOURCE
...

```

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [October 15, 2021, 4:06am UTC](https://discuss.gradle.org/t/test-task-sources/41192/3 "2021-10-15T04:06:11Z")

</div>

`NO-SOURCE` is a generic term used by Gradle to represent a task that was skipped when “skip-when-empty” inputs are in fact empty. It is not specifically related to “source code”.  
[https://docs.gradle.org/current/userguide/more\_about\_tasks.html#sec:task\_input\_output\_annotations](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_input_output_annotations)

 ![image](https://global.discourse-cdn.com/gradle/original/2X/b/b11eb93a3a4d4429c7bd2f43446fe7a17a0b5540.png)

It appears that if the `testClassesDirs` contain classes, then the task should not be skipped. If you have test classes in those dirs then I’m not sure why it’s reporting NO-SOURCE.

> <https://github.com/gradle/gradle/blob/master/subprojects/testing-jvm/src/main/java/org/gradle/api/tasks/testing/Test.java#L1193>

Side note; You mentioned test jars, AFAIK Gradle still doesn’t support running tests from jars. An old post about it [Gradle junit runs: pick tests (test class names) from jar file](https://discuss.gradle.org/t/gradle-junit-runs-pick-tests-test-class-names-from-jar-file/560)

---

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [October 15, 2021, 1:17pm UTC](https://discuss.gradle.org/t/test-task-sources/41192/4 "2021-10-15T13:17:23Z")

</div>

Thanks for the reply @Chris_Dore

I guess I was not clear about using “jar”. Its a confusing process. We have a project named `hibernate-core` which is based on Java EE (at the source level). We need to also publish a variation of that using the new Jakarta EE contracts under `hibernate-core-jakarta`. This is all done “on the fly”. The build for `hibernate-core-jakarta`:

1. Takes the main jar from `hibernate-core` and transforms it as its own jar
2. Takes the test jar from `hibernate-core` and unpacks it
3. Takes the unpacked test jar and applies the transformation into another directory
4. Configures its test task to
  - use the outputs from (1) and (3) for its classpath
  - use the output from (3) for its classesDir

So by the time `:hibernate-core-jakarta:test` is executed, that classesDir will exist. But it does not at configuration time. Could that be an issue? I can’t imagine so since its essentially what happens with the test task normally.

Though maybe its related to _how_ I configure it? Since I call `files( project.transformedTestDir )` at config time? For what it is worth, I tried using providers instead but same result

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [December 12, 2021, 4:28am UTC](https://discuss.gradle.org/t/test-task-sources/41192/5 "2021-12-12T04:28:06Z")

</div>

Mind sharing your solution @Steve_Ebersole, as the tests are run now as expected in your build?

---

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [December 12, 2021, 2:06pm UTC](https://discuss.gradle.org/t/test-task-sources/41192/6 "2021-12-12T14:06:17Z")

</div>

I did get it working, but to be honest, I forget what exactly worked. We ended up just moving to Jakarta Persistence at the source level and so that stuff is no longer part of the build.
