-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create abstraction for library dependencies for instrumentation. (#977)
* Create abstraction for library dependencies for instrumentation. Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
Showing
78 changed files
with
336 additions
and
905 deletions.
There are no files selected for viewing
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
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,76 @@ | ||
/** Common setup for manual instrumentation of libraries and auto instrumentation. */ | ||
|
||
|
||
/** | ||
* We define three dependency configurations to use when adding dependencies to libraries being | ||
* instrumented. | ||
* | ||
* - library: A dependency on the instrumented library. Results in the dependency being added to | ||
* compileOnly and testImplementation. If the build is run with -PtestLatestDeps=true, the | ||
* version when added to testImplementation will be overridden by `+`, the latest version | ||
* possible. For simple libraries without different behavior between versions, it is possible | ||
* to have a single dependency on library only. | ||
* | ||
* - testLibrary: A dependency on a library for testing. This will usually be used to either | ||
* a) use a different version of the library for compilation and testing and b) to add a helper | ||
* that is only required for tests (e.g., library-testing artifact). The dependency will be | ||
* added to testImplementation and will have a version of `+` when testing latest deps as | ||
* described above. | ||
* | ||
* - latestDepTestLibrary: A dependency on a library for testing when testing of latest dependency | ||
* version is enabled. This dependency will be added as-is to testImplementation, but only if | ||
* -PtestLatestDeps=true. The version will not be modified but it will be given highest | ||
* precedence. Use this to restrict the latest version dependency from the default `+`, for | ||
* example to restrict to just a major version by specifying `2.+`. | ||
*/ | ||
|
||
ext.testLatestDeps = findProperty('testLatestDeps') | ||
configurations { | ||
// library is where to define dependencies on the library that is being instrumented. It will not | ||
// be packaged in the agent but will be available at runtime for tests. | ||
library { | ||
canBeResolved = false | ||
canBeConsumed = false | ||
} | ||
testLibrary { | ||
canBeResolved = false | ||
canBeConsumed = false | ||
} | ||
latestDepTestLibrary { | ||
canBeResolved = false | ||
canBeConsumed = false | ||
} | ||
[library, testLibrary].each {configuration -> | ||
// We use whenObjectAdded and copy into the real configurations instead of extension to allow | ||
// mutating the version for latest dep tests. | ||
configuration.dependencies.whenObjectAdded { | ||
def dep = it.copy() | ||
if (testLatestDeps) { | ||
dep.version { | ||
it.require '+' | ||
} | ||
} | ||
testImplementation.dependencies.add(dep) | ||
} | ||
} | ||
if (testLatestDeps) { | ||
latestDepTestLibrary.dependencies.whenObjectAdded { | ||
def dep = it.copy() | ||
def declaredVersion = dep.version | ||
dep.version { | ||
it.strictly declaredVersion | ||
} | ||
testImplementation.dependencies.add(dep) | ||
} | ||
} | ||
compileOnly.extendsFrom(library) | ||
} | ||
|
||
if (testLatestDeps) { | ||
afterEvaluate { | ||
def latestDepTest = tasks.findByName('latestDepTest') | ||
if (latestDepTest) { | ||
tasks.test.dependsOn latestDepTest | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.