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

Support dependencies resolved outside of a Project context #24

Merged
merged 4 commits into from
Apr 19, 2023

Conversation

bigdaz
Copy link
Member

@bigdaz bigdaz commented Apr 11, 2023

Previously, we were ignoring any dependency resolution that occurred outside the
context of a Gradle Project. This meant that any dependencies resolved in the
context of a Settings script were not being captured.

By tracking the 'buildPath' and the 'projectPath' separately, we can now collect
all dependency resolution.

Due to a limitation in the events being processed, all non-project resolution will
be allocated to a single manifest for the entire build process. It may be possible
later to make this more precise, and assign resolution to a specific build process.

@bigdaz bigdaz requested a review from erichaagdev April 11, 2023 02:00
@bigdaz bigdaz force-pushed the dd/settings-dependencies branch 2 times, most recently from b6eae8b to d6093ad Compare April 11, 2023 21:08
Comment on lines 58 to 63
static String getTestGradleVersion() {
System.getProperty("testGradleVersion", GradleVersion.current().version)
}

static settingsPluginsAreSupported() {
return GradleVersion.version(testGradleVersion) >= GradleVersion.version("6.0")
Copy link
Member

Choose a reason for hiding this comment

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

I recommend consistent usage of return types and the return keyword. Either use them or don't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Roger that. Good feedback.

manifestHasPlugin2("project :included-plugin:a")
}

private void createMultiProjectBuildWithPlugins(TestFile rootDir) {
Copy link
Member

Choose a reason for hiding this comment

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

The formatting for these multiline strings is very strange. 🤔

Comment on lines +193 to +190
if (expected.package_url != null) {
assert actual.package_url == expected.package_url
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might you want to assert that it isn't present, rather than not asserting anything at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the package_url will be present, but this test isn't asserting anything about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth continuing to assert that it is set to a non-empty value, beginning with pkg:, even if you're not asserting anything else about it?

// TODO: See the Gradle Enterprise Build Scan Plugin: `ConfigurationResolutionCapturer_5_0`

if (projectIdentityPath == null && rootComponent.dependencies.isEmpty()) {
// Not a project configuration, and no dependencies to extract: can safely ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is a ResolveConfigurationDependenciesBuildOperationType event issued in this case then?

Copy link
Member Author

Choose a reason for hiding this comment

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

This happens when a configuration is resolved that doesn't have any dependencies configured. I'm pretty sure the main case this happens is when resolving a classpath configuration when no plugins (or other classpath dependencies) have been declared.

Comment on lines +79 to +84
private fun manifestName(config: ResolvedConfiguration): String {
if (config.identityPath != null) {
return "project ${config.identityPath}"
}
return "build ${config.buildPath}"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting way of differentiating names. Given these names may be rendered in the GitHub UI, might it be good to capitalize the first letters of Project and Build?

Copy link
Contributor

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

A few minor comments, otherwise LGTM!

Settings script dependencies are not currently captured, whether added by
a `buildscript` block or via `plugins`.
Previously, we were ignoring any dependency resolution that occurred outside the
context of a Gradle Project. This meant that any dependencies resolved in the
context of a Settings script were not being captured.

By tracking the 'buildPath' and the 'projectPath' separately, we can now collect
all dependency resolution.

Due to a limitation in the events being processed, all non-project resolution will
be allocated to a single manifest for the entire build process. It may be possible
later to make this more precise, and assign resolution to a specific build process.
- Only test Settings plugins on Gradle >= 6.0. Earlier versions of Gradle
did not support the `plugins` block within a Settings script.
- Do not specify a version for subproject plugin.
- Avoid using implicit return in Groovy
- Reformat Groovy code
@bigdaz bigdaz merged commit f3857ab into main Apr 19, 2023
@bigdaz bigdaz deleted the dd/settings-dependencies branch April 19, 2023 00:04
@bigdaz bigdaz linked an issue Apr 29, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Settings script dependencies are not collected
3 participants