PS
if I run the same task with gradle 8.2 then I receive error
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileTestJava'.
> Resolving dependency configuration 'testAnnotationProcessor' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'testAnnotationProcessor' should be resolved.
Where exactly do you have the Java file of the unit test? Task :app:compileTestJava NO-SOURCE suggests that you do not have it in the correct directory.
Besides that, the java.srcDir and resources.srcDir are pointless, those are the defaults anyway.
The testAnnotationProcessor error suggests that you use some plugin that is not compatible with the Gradle version you try to use. Can you share a build --scan or at least --stacktrace output? That should show where exactly this is coming from.
Besides that, the java.srcDir and resources.srcDir are pointless, those are the defaults anyway.
If I dont put it that way, then sourceSets are not available inside sampleTask.
Here is the error message for this case
A problem occurred evaluating project ':app'.
> Could not get unknown property 'test' for SourceSet container of type org.gradle.api.internal.tasks.DefaultSourceSetContainer.
Ah, that means there is no source set called test.
That’s probably different in an Android build then.
I’m not really familiar with Android builds.
Are you sure you are trying to do the right thing?
Also I’d like to suggest using Kotlin DSL instead of Groovy DSL.
By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support when using a good IDE like IntelliJ or Android Studio.
Ah, that means there is no source set called test.
That’s probably different in an Android build then.
I’m not really familiar with Android builds.
there is a task which shows that sourceSets are available,
I’ll provide output of this task below.
These sourceSets are not available through sourceSets or project.sourceSets.
Instead I can call android.sourceSets.getbyName("test"), but it is not the same.
It’s AndroidSourceSet and there is no output property in it.
Are you sure you are trying to do the right thing?
Doc says that I have to provide testClassesDirs and classPath. So I was trying to get it from sourceSets, I’m not sure if its the right way on android, I just followed examples
In order to operate, the `Test` task type requires just two pieces of information:
* Where to find the compiled test classes (property: [Test.getTestClassesDirs()])
* The execution classpath, which should include the classes under test as well as the test library that you’re using (property: [Test.getClasspath()])
When you’re using a JVM language plugin — such as the [Java Plugin] — you will automatically get the following:
* A dedicated `test` source set for unit tests
* A `test` task of type `Test` that runs those unit tests
The testAnnotationProcessor error suggests that you use some plugin that is not compatible with the Gradle version you try to use. Can you share a build --scan or at least --stacktrace output? That should show where exactly this is coming from.
here is build scan for gradle 8.2. This version gives error, 8.0 runs fine
Probably another effect of what you try.
As you see in that build scan in the deprecations, the 4 test related configurations are created that are reserved for creation by Gradle.