Skip to content

Commit

Permalink
Deprecate ProjectDependency#getDependencyProject (gradle#30447)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandort authored Sep 24, 2024
2 parents a4472e3 + 61c3d08 commit 22904d9
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class DependencyHandlerExtensionsTest {
}

@Test
@Suppress("DEPRECATION")
fun `given path and configuration, 'project' extension will build corresponding map`() {

val dependencyHandlerMock = newDependencyHandlerMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ Calling the following methods on link:{javadocPath}/org/gradle/api/artifacts/Con
- addLater(Provider)
- addAllLater(Provider)

[[deprecate_get_dependency_project]]
==== Deprecated `ProjectDependency#getDependencyProject()`

The link:{javadocPath}/org/gradle/api/artifacts/ProjectDependency.html#getDependencyProject()[`ProjectDependency#getDependencyProject()`] method has been deprecated and will be removed in Gradle 9.0.

Accessing the mutable project instance of other projects should be avoided.

[[deprecate_legacy_configuration_get_files]]
==== Deprecated `ResolvedConfiguration.getFiles()` and `LenientConfiguration.getFiles()`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ task checkDeps {
succeeds 'checkDeps'
}

@ToBeFixedForConfigurationCache(because = "Task uses the Configuration API")
def "understands project notations"() {
when:
createDirs("otherProject")
Expand All @@ -107,14 +106,16 @@ dependencies {
}
task checkDeps {
def rootOne = configurations.conf.incoming.resolutionResult.rootComponent
def rootTwo = configurations.confTwo.incoming.resolutionResult.rootComponent
doLast {
def deps = configurations.conf.incoming.dependencies
assert deps.size() == 1
assert deps.find { it.dependencyProject.path == ':otherProject' && it.targetConfiguration == null }
def depsOne = rootOne.get().dependencies*.requested
assert depsOne.size() == 1
assert depsOne.find { it.projectPath == ':otherProject' }
deps = configurations.confTwo.incoming.dependencies
assert deps.size() == 1
assert deps.find { it.dependencyProject.path == ':otherProject' && it.targetConfiguration == 'otherConf' }
def depsTwo = rootTwo.get().dependencies*.requested
assert depsTwo.size() == 1
assert depsTwo.find { it.projectPath == ':otherProject' }
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ task verify {
executer.expectDocumentedDeprecationWarning("The Configuration.files(Closure) method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use Configuration.getIncoming().artifactView(Action) with a componentFilter instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_filtered_configuration_file_and_filecollection_methods")
executer.expectDocumentedDeprecationWarning("The ResolvedConfiguration.getFiles() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use Configuration#getFiles instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_legacy_configuration_get_files")
executer.expectDocumentedDeprecationWarning("The LenientConfiguration.getFiles() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use a lenient ArtifactView instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_legacy_configuration_get_files")
executer.expectDocumentedDeprecationWarning("The ProjectDependency.getDependencyProject() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_get_dependency_project")
run "verify"

then:
Expand Down Expand Up @@ -147,6 +148,7 @@ task verify {
executer.expectDocumentedDeprecationWarning("The Configuration.files(Closure) method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use Configuration.getIncoming().artifactView(Action) with a componentFilter instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_filtered_configuration_file_and_filecollection_methods")
executer.expectDocumentedDeprecationWarning("The ResolvedConfiguration.getFiles() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use Configuration#getFiles instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_legacy_configuration_get_files")
executer.expectDocumentedDeprecationWarning("The LenientConfiguration.getFiles() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Use a lenient ArtifactView instead. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_legacy_configuration_get_files")
executer.expectDocumentedDeprecationWarning("The ProjectDependency.getDependencyProject() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_get_dependency_project")
run "verify"

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,22 @@ project(':b') {
"project(':')" | "root project :" | ":outgoingVariants"
"'org:included:1.0'" | "project :included" | ":included:outgoingVariants"
}

def "getDependencyProject is deprecated"() {
buildFile << """
configurations {
dependencyScope("foo")
}
dependencies {
foo(project)
}
configurations.foo.dependencies.iterator().next().getDependencyProject()
"""

expect:
executer.expectDocumentedDeprecationWarning("The ProjectDependency.getDependencyProject() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecate_get_dependency_project")
succeeds("help")
}
}
Loading

0 comments on commit 22904d9

Please sign in to comment.