Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disableTestTask configures the task but should not #615

Open
hfhbd opened this issue May 22, 2024 · 8 comments
Open

disableTestTask configures the task but should not #615

hfhbd opened this issue May 22, 2024 · 8 comments
Assignees
Labels
Bug Bug issue type S: confirmed Status: bug is reproduced or present S: postponed Status: work on the issue is not in the short term plans

Comments

@hfhbd
Copy link

hfhbd commented May 22, 2024

Describe the bug
I use the jvm-test-suite plugin and add an integrationTest but I don't want to include the task/test results in kover.

Errors
./gradlew build =>

Could not determine the dependencies of task ':koverGenerateArtifactJvm'.
> Could not create task ':integrationTest'.
   > Cannot query the value of this provider because it has no value available.

Expected behavior
./gradlew build => no error

Reproducer

plugins {
    kotlin("jvm") version "2.0.0"
    id("jvm-test-suite")
    id("org.jetbrains.kotlinx.kover") version "0.8.0"
}

kotlin.jvmToolchain(21)

repositories {
    mavenCentral()
}

testing.suites {
    named("test", JvmTestSuite::class) {
        useKotlinTest()
    }
    register("integrationTest", JvmTestSuite::class) {
        useKotlinTest()
        targets.configureEach {
            testTask {
                environment("foo", providers.gradleProperty("NOT-SET").get())
            }
        }
    }
}

kover.currentProject {
    instrumentation {
        disabledForTestTasks.add("integrationTest")
    }
    sources {
        excludedSourceSets.add("integrationTest")
    }
}

Reports
If applicable, report files or screenshots.

Environment

  • Kover Gradle Plugin version: 0.8.0
  • Gradle version: 8.7
  • Kotlin project type: Kotlin JVM
  • Coverage Toolset (if customized in build script): nA
  • Other context important for this bug: nA
@hfhbd hfhbd added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels May 22, 2024
@hfhbd
Copy link
Author

hfhbd commented May 29, 2024

Alternatively, only depend on tasks.test ("unit-test" type when using jvm-test-suite plugin) by default and you need to opt-in to depend on other test tasks.
This also allows you to remove some filtering hacks in kover:

kover.currentProject {
    sources {
      srcDirs("integrationTest") // same behavior like builtin sourceSets
    }
    instrumentation {
      include(tests.integrationTest)
     }
}

@shanshin
Copy link
Collaborator

Hi,
this is because Kover Gradle Plugin use the matching function to locate test tasks but it is not lazy - it causes the creation of an instance of the task. For this reason, even if you exclude a task by name using matching, it is still created.

This can be circumvented by using the new named function, however it will only work in Gradle starting with version 8.6

@hfhbd
Copy link
Author

hfhbd commented May 29, 2024

But what about using opt-in of other tasks instead to not configure the tasks by default?

@shanshin
Copy link
Collaborator

But what about using opt-in of other tasks instead to not configure the tasks by default?

This can be done, but in this case it is necessary to significantly redesign the workflow for the plugin.

Since you are using Gradle version 8.7, we will implement usage of the new named function, and in this case the integrationTest task instance will not be created when writing

kover.currentProject {
    instrumentation {
        disabledForTestTasks.add("integrationTest")
    }
}

@shanshin
Copy link
Collaborator

shanshin commented Jun 3, 2024

Unfortunately, the named {} function in Gradle still contains a similar error, and it causes the creation of all tasks (see example).
Therefore, at the moment it is difficult to write a search for test tasks by name without configuring all test tasks.

The use of named("name") is unreliable, because the task can be created after, and the use of TaskProviders requires significant changing of the DSL.

We are waiting for the fix to be released in Gradle.

@shanshin shanshin added S: confirmed Status: bug is reproduced or present S: postponed Status: work on the issue is not in the short term plans and removed S: untriaged Status: issue reported but unprocessed labels Jun 3, 2024
@hfhbd
Copy link
Author

hfhbd commented Jul 17, 2024

I found a solution (for my use-case): I switched to the new settings plugin and everything works now without configuring the integration test tasks, nice!

But I have one question left: How do I setup rules in settings plugin?

@shanshin
Copy link
Collaborator

But I have one question left: How do I setup rules in settings plugin?

There is no verify task in settings plugin right now, but I think we will add it in the next release

@shanshin
Copy link
Collaborator

shanshin commented Sep 3, 2024

@hfhbd, verification was added in 0.9.0-RC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: confirmed Status: bug is reproduced or present S: postponed Status: work on the issue is not in the short term plans
Projects
None yet
Development

No branches or pull requests

2 participants