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

Add Upgrade Note for Strongly Typed Dependencies in Test Suites #22778

Merged
merged 9 commits into from Nov 17, 2022
Expand Up @@ -95,6 +95,7 @@ Common values are available as constants in link:{javadocPath}/org/gradle/api/at

Here are several examples to illustrate the configurability of test suites.

[[sec:declare_an_additional_test_suite]]
== Declare an additional test suite
====
include::sample[dir="snippets/testing/test-suite-plugin/groovy",files="build.gradle[tags=configure-testing-extension]"]
Expand Down Expand Up @@ -221,6 +222,7 @@ include::sample[dir="snippets/testing/test-suite-multi-configure-each-extracted/
<2> Apply the closure to a test suite, using the default (`test`) test suite
<3> Alternate means of applying a configuration closure to a test suite outside of its declaration, using the `integrationTest` test suite

[[sec:differences_with_top_level_dependencies]]
== Differences between the test suite `dependencies` and the top-level `dependencies` blocks

Gradle 7.6 changed the API of the test suite's `dependencies` block to be more strongly-typed.
Expand Down
Expand Up @@ -117,6 +117,59 @@ PMD has been updated to https://pmd.github.io/pmd-6.48.0/pmd_release_notes.html[
When configuring an executable explicitly for link:{groovyDslPath}/org.gradle.api.tasks.compile.ForkOptions.html#org.gradle.api.tasks.compile.ForkOptions:executable[`JavaCompile`] or link:{groovyDslPath}/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:executable[`Test`] tasks, Gradle will now emit an error if this executable does not exist.
In the past, the task would be executed with the default toolchain or JVM running the build.

==== Changes to dependency declarateions in Test Suites
tresat marked this conversation as resolved.
Show resolved Hide resolved

As part of the ongoing effort to improve Test Suites, dependency declarations using its nested `dependencies` block are <<jvm_test_suite_plugin.adoc#sec:differences_with_top_level_dependencies, now strongly typed>>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As part of the ongoing effort to improve Test Suites, dependency declarations using its nested `dependencies` block are <<jvm_test_suite_plugin.adoc#sec:differences_with_top_level_dependencies, now strongly typed>>.
Dependency declarations in the Test Suites `dependencies` block are <<jvm_test_suite_plugin.adoc#sec:differences_with_top_level_dependencies, now strongly typed>>.

Suggestion: as an incubating API, I assume users are aware we are continually tweaking and improving things. Better to avoid the confusing pronoun usage, eliminate the intro, and keep the sentence trim.

Copy link
Member Author

@tresat tresat Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the intro here. I think part of the reason for this note existing is to head of criticism in the form of "Why did this minor version upgrade suddenly break my build?" Re-emphasizing the incubating and changing status of the API seems worthwhile, and might prevent some angry feedback/issues. I like the changes after that clause.

This will help make this incubating API more discoverable and easier to use in an IDE.

In some case, this requires syntax changes.
tresat marked this conversation as resolved.
Show resolved Hide resolved
For example, build scripts that previously added Test Suite dependencies with the following syntax:

```kotlin
testing {
suites {
register<JvmTestSuite>("integrationTest") {
dependencies {
implementation(project)
}
}
}
}
```

will now fail to compile, with a message like:

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

To fix this, replace the reference to `project` with a call to `project()`:

```kotlin
testing {
suites {
register<JvmTestSuite>("integrationTest") {
dependencies {
implementation(project())
}
}
}
}
```

There are other related changes, such as:
tresat marked this conversation as resolved.
Show resolved Hide resolved

- You cannot use `Provider<String>` as a dependency declaration.
- You cannot use a `Map` as a dependency declaration for Kotlin or Java.
- You cannot use a bundle as a dependency declaration directly (`implementation(libs.bundles.testing)`), instead you have to use `implementation.bundle(libs.bundles.testing)`.
tresat marked this conversation as resolved.
Show resolved Hide resolved

For more information, see the updated <<jvm_test_suite_plugin.adoc#sec:declare_an_additional_test_suite, declare an additional test suite>> example in the JVM Test Suite Plugin section of the user guide and the link:{groovyDslPath}/org.gradle.api.artifacts.dsl.DependencyAdder.html[`DependencyAdder`] page in the DSL reference.

=== Deprecations

[[invalid_toolchain_specification_deprecation]]
Expand Down