jdaugherty commented on code in PR #43:
URL:
https://github.com/apache/grails-gradle-publish/pull/43#discussion_r4190492515
##########
plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy:
##########
@@ -1035,36 +1032,15 @@ Note: properties are read as Gradle properties (the
root project's gradle.proper
* resolved classpaths the pom is completed from.
*/
protected void configureModuleMetadataVersions(Project project,
GrailsPublishExtension gpe, String publicationName, List<String>
configurationNames) {
+ // the action runs when the module metadata is generated, so it is
given values and providers only: with the
+ // configuration cache, neither the project nor this extension is
available then
+ Provider<Boolean> transitiveDependencies = gpe.transitiveDependencies
+ Provider<Map<String, String>> resolvedVersions =
resolvedVersionsProvider(project, transitiveDependencies, configurationNames)
Review Comment:
Fixed in 187e710: there is one provider per set of configurations per
project, shared by the pom and the module metadata of a publication. It
resolves its configurations once, however often it is queried.
##########
plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy:
##########
@@ -815,26 +822,16 @@ Note: properties are read as Gradle properties (the root
project's gradle.proper
}
NodeList dependencyNodes = (nodes.get(0) as
Node).getAt(dependencyQName) as NodeList
- LinkedHashSet<ResolvedArtifact> resolvedArtifacts = []
- for (String configurationName : configurationNames) {
- def configuration =
project.configurations.findByName(configurationName)
- if (configuration != null) {
-
resolvedArtifacts.addAll(configuration.resolvedConfiguration.resolvedArtifacts)
- }
- }
-
- dependencyNodes.findAll { dependencyNode ->
+ Map<String, String> versions = resolvedVersions.get()
Review Comment:
Fixed in 187e710. The pom only queries the versions once it has found a
dependency without one, and the module metadata on the first dependency without
one. Unit tests use a provider that throws when queried. The javadoc now says
"only queried when a dependency has no version".
##########
plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy:
##########
@@ -1233,5 +1254,114 @@ Note: properties are read as Gradle properties (the
root project's gradle.proper
}
}
}
-}
+ /**
+ * Completes the generated pom: removes the dependencyManagement section
(unless the project is a platform),
+ * applies the pom customization, and fills in the versions of
dependencies declared without one.
+ *
+ * The action is part of the state of the pom generation task, so it only
holds values and providers, which keeps
+ * it compatible with the configuration cache. The versions are read from
a provider, which the configuration
+ * cache evaluates when it stores the task.
+ */
+ @PackageScope
+ static class PomXmlAction implements Action<XmlProvider> {
+
+ private final MavenPom pom
+ private final boolean javaPlatform
+ private final Provider<Closure> pomCustomization
+ private final Provider<Boolean> transitiveDependencies
+ private final Provider<Map<String, String>> resolvedVersions
+
+ PomXmlAction(MavenPom pom, boolean javaPlatform, Provider<Closure>
pomCustomization,
+ Provider<Boolean> transitiveDependencies,
Provider<Map<String, String>> resolvedVersions) {
+ this.pom = pom
+ this.javaPlatform = javaPlatform
+ this.pomCustomization = pomCustomization
+ this.transitiveDependencies = transitiveDependencies
+ this.resolvedVersions = resolvedVersions
+ }
+
+ @Override
+ void execute(XmlProvider xml) {
+ Node pomNode = xml.asNode()
+
+ if (!javaPlatform) {
+ // Spring boot dependency management plugin will add the
dependencyManagement section,
+ // we do not want to publish this information as we will
determine the specific versions
+ // and set them instead
+ NodeList dependencyManagement = (NodeList)
pomNode.get('dependencyManagement')
+ if (dependencyManagement) {
+ dependencyManagement.replaceNode {}
+ }
+ }
+
+ if (pomCustomization.isPresent()) {
+ Closure customization = pomCustomization.get()
+ customization.delegate = pom
+ customization.resolveStrategy = Closure.DELEGATE_FIRST
+ customization.call(xml)
+ }
+
+ // fix dependencies without a version, this can occur when the
spring dependency management plugin is used
+ // disabling that plugin will cause gradle to fail on any
unresolved, or by disabling the check with:
+ // https://github.com/gradle/gradle/issues/23030
+ //tasks.withType(GenerateModuleMetadata).configureEach {
+ //
suppressedValidationErrors.add('dependencies-without-versions')
+ //}
+ if (transitiveDependencies.get()) {
+ setDependencyVersions(pomNode, resolvedVersions)
+ }
+ }
+ }
+
+ /**
+ * Fills in the versions the Gradle module metadata is missing, see
+ * {@link #configureModuleMetadataVersions(Project,
GrailsPublishExtension, String, List)}.
+ *
+ * The action is part of the state of the module metadata task, so it only
holds values and providers, which keeps
+ * it compatible with the configuration cache. The versions are read from
a provider, which the configuration
+ * cache evaluates when it stores the task.
+ */
+ @PackageScope
+ static class ModuleMetadataVersionsAction implements Action<Task> {
+
+ private final String publicationName
+ private final Provider<Boolean> transitiveDependencies
+ private final Provider<Map<String, String>> resolvedVersions
+
+ ModuleMetadataVersionsAction(String publicationName, Provider<Boolean>
transitiveDependencies,
+ Provider<Map<String, String>>
resolvedVersions) {
+ this.publicationName = publicationName
+ this.transitiveDependencies = transitiveDependencies
+ this.resolvedVersions = resolvedVersions
+ }
+
+ @Override
+ void execute(Task task) {
+ if (!transitiveDependencies.get()) {
+ return
+ }
+ File moduleFile = ((GenerateModuleMetadata)
task).outputFile.get().asFile
+ Map<String, String> versions = resolvedVersions.get()
+ Map module = new JsonSlurper().parse(moduleFile, 'UTF-8') as Map
+ boolean changed = false
+ for (Map variant : (module.variants ?: []) as List<Map>) {
+ for (Map dependency : (variant.dependencies ?: []) as
List<Map>) {
+ Map version = dependency.version as Map
+ if (version?.requires || version?.strictly ||
version?.prefers) {
+ continue
+ }
+ String resolved =
versions["${dependency.group}:${dependency.module}" as String]
+ if (resolved == null) {
Review Comment:
Fixed in 187e710: both paths use `!resolved`, and a unit test checks that
both fail on an empty version.
##########
plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy:
##########
@@ -1233,5 +1254,114 @@ Note: properties are read as Gradle properties (the
root project's gradle.proper
}
}
}
-}
+ /**
+ * Completes the generated pom: removes the dependencyManagement section
(unless the project is a platform),
+ * applies the pom customization, and fills in the versions of
dependencies declared without one.
+ *
+ * The action is part of the state of the pom generation task, so it only
holds values and providers, which keeps
+ * it compatible with the configuration cache. The versions are read from
a provider, which the configuration
+ * cache evaluates when it stores the task.
+ */
+ @PackageScope
+ static class PomXmlAction implements Action<XmlProvider> {
+
+ private final MavenPom pom
+ private final boolean javaPlatform
+ private final Provider<Closure> pomCustomization
+ private final Provider<Boolean> transitiveDependencies
+ private final Provider<Map<String, String>> resolvedVersions
+
+ PomXmlAction(MavenPom pom, boolean javaPlatform, Provider<Closure>
pomCustomization,
+ Provider<Boolean> transitiveDependencies,
Provider<Map<String, String>> resolvedVersions) {
+ this.pom = pom
+ this.javaPlatform = javaPlatform
+ this.pomCustomization = pomCustomization
+ this.transitiveDependencies = transitiveDependencies
+ this.resolvedVersions = resolvedVersions
+ }
+
+ @Override
+ void execute(XmlProvider xml) {
+ Node pomNode = xml.asNode()
+
+ if (!javaPlatform) {
+ // Spring boot dependency management plugin will add the
dependencyManagement section,
+ // we do not want to publish this information as we will
determine the specific versions
+ // and set them instead
+ NodeList dependencyManagement = (NodeList)
pomNode.get('dependencyManagement')
+ if (dependencyManagement) {
+ dependencyManagement.replaceNode {}
+ }
+ }
+
+ if (pomCustomization.isPresent()) {
+ Closure customization = pomCustomization.get()
+ customization.delegate = pom
+ customization.resolveStrategy = Closure.DELEGATE_FIRST
+ customization.call(xml)
+ }
+
+ // fix dependencies without a version, this can occur when the
spring dependency management plugin is used
+ // disabling that plugin will cause gradle to fail on any
unresolved, or by disabling the check with:
+ // https://github.com/gradle/gradle/issues/23030
+ //tasks.withType(GenerateModuleMetadata).configureEach {
Review Comment:
Removed in 187e710; the comment above the call now just says what it does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]