Test task sources

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:

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

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

// `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:

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

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

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.

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

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