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

7.6 RC3: DependencyAdder.invoke cannot be called with the arguments supplied #22720

Closed
ianbrandt opened this issue Nov 14, 2022 · 4 comments
Closed
Assignees
Labels
a:documentation Documentation content in:test-suites Work related to the JvmTestSuite Plugin
Milestone

Comments

@ianbrandt
Copy link

ianbrandt commented Nov 14, 2022

Expected Behavior

Precompiled script plugins configuring a project dependency for an additional test suite via the JVM Test Site Plugin continue to compile after upgrading to Gradle 7.6 RC3.

Current Behavior

The script fails to compile:

e: C:\Dev\Repos\SDKotlin\sd-kotlin-talks\build-logic\src\main\kotlin\org.sdkotlin.build.test.integration-test-suite.gradle.kts: (20, 5): None of the following functions can be called with the arguments supplied: 
public operator fun DependencyAdder.invoke(dependencyNotation: CharSequence): Unit defined in org.gradle.kotlin.dsl
public operator fun DependencyAdder.invoke(dependency: Dependency): Unit defined in org.gradle.kotlin.dsl
public operator fun DependencyAdder.invoke(files: FileCollection): Unit defined in org.gradle.kotlin.dsl
public operator fun DependencyAdder.invoke(dependency: Provider<out Dependency>): Unit defined in org.gradle.kotlin.dsl
public operator fun DependencyAdder.invoke(externalModule: ProviderConvertible<out MinimalExternalModuleDependency>): Unit defined in org.gradle.kotlin.dsl

FAILURE: Build failed with an exception.

Context

I'm unable to upgrade to Gradle 7.6.

Steps to Reproduce

Reproducer: https://github.com/sdkotlin/sd-kotlin-talks/tree/a54afe81013c1806550ff23478efe48973033deb

Line in error: https://github.com/sdkotlin/sd-kotlin-talks/blob/a54afe81013c1806550ff23478efe48973033deb/build-logic/src/main/kotlin/org.sdkotlin.build.test.integration-test-suite.gradle.kts#L20

Your Environment

Gradle 7.6-rc3
Kotlin 1.7.21
Java 11.0.17

@tresat
Copy link
Member

tresat commented Nov 17, 2022

Hi Ian, this is an expected change to the @Incubating Test Suites API we're making with Gradle 7.6. This is part of an effort to make the API used to add dependencies more discoverable and strongly typed. It should have the benefit of making the testing DSL easier to work with in your IDE.

Take a look at the Introduced strongly-typed dependencies block for JVM test suites section in the release notes and the updated example in the JVM Test Suite Plugin page of the user guide. In short, you need to switch from referencing the current project via project to calling the project() method.

The methods used to add dependencies to Test Suites differ from those used in the top-level block. In Gradle 7.6, Test Suites make use of a new type DependencyAdder, which accepts a ProjectDependency, not a Project, as in the top-level dependencies block. You need to call the project() method to obtain one of these.

This is a subtle change, and definitely a possible stumbling block. Thanks for pointing it out! We'll add a note to the upgrade guide.

@tresat tresat closed this as completed Nov 17, 2022
bot-gradle added a commit that referenced this issue Nov 17, 2022
…ncies in Test Suites

<!--- The issue this PR addresses -->
Fixes #22720

Co-authored-by: Thomas Tresansky <ttresansky@gradle.com>
@ianbrandt
Copy link
Author

Thanks @tresat, I was able to upgrade to 7.6 RC3 successfully using project() instead of project.

@bric3
Copy link
Contributor

bric3 commented Nov 26, 2022

For people discovering this issue with versions catalog items, you need to change the declarations this way

  testing {
      suites {
          val test by getting(JvmTestSuite::class) {
              useJUnitJupiter(libs.versions.junit.jupiter.get())
              dependencies {
-                 implementation(libs.assertj)
+                 implementation.add(libs.assertj)
-                 implementation(libs.bundles.batik)
+                 implementation.bundle(libs.bundles.batik)
              }
          }

To find the relevant method, inspect DependencyAdder doc.

As this isn't clearly explained in neither the release note nor the differences doc. There's only a mention of the bundle lost in a long list. I believe some examples would have been better in this case.

@tresat
Copy link
Member

tresat commented Apr 15, 2024

As this isn't clearly explained in neither the release note nor the differences doc. There's only a mention of the bundle lost in a long list. I believe some examples would have been better in this case.

@bric3 - Finally got around to updating the docs here: #28828. Thank you for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:documentation Documentation content in:test-suites Work related to the JvmTestSuite Plugin
Projects
None yet
Development

No branches or pull requests

4 participants