-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a utility function for copying project dependencies (#7)
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
project-accessors/src/main/kotlin/co/hinge/gradle/projectaccessors/ProjectDependencies.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |