Skip to content

Commit

Permalink
Add a utility function for copying project dependencies (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansman authored Mar 29, 2024
1 parent 79990c3 commit 742c750
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package co.hinge.gradle.projectaccessors

import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.VersionConstraint

/**
* Returns a copy of this [ProjectDependency] with specified attributes.
*
* @receiver The [ProjectDependency] to copy.
* @param targetConfiguration The requested target configuration of this dependency. This is the name of the configuration in the target module that should be used when selecting the matching configuration. If null, a default configuration will be used.
* @param isTransitive Whether this dependency should be resolved including or excluding its transitive dependencies. The artifacts belonging to this dependency might themselves have dependencies on other artifacts. The latter are called transitive dependencies.
* @param endorseStrictVersions Will, if true, endorse version constraints with [VersionConstraint.getStrictVersion] from the target module. Endorsing strict versions of another module/platform means that all strict versions will be interpreted during dependency resolution as if they were defined by the endorsing module.
*/
fun ProjectDependency.copy(
targetConfiguration: String? = getTargetConfiguration(),
isTransitive: Boolean = isTransitive(),
endorseStrictVersions: Boolean = isEndorsingStrictVersions,
) : ProjectDependency = copy().apply {
setTargetConfiguration(targetConfiguration)
setTransitive(isTransitive)
if (endorseStrictVersions) {
endorseStrictVersions()
} else {
doNotEndorseStrictVersions()
}
}

0 comments on commit 742c750

Please sign in to comment.