matrei commented on code in PR #39:
URL:
https://github.com/apache/grails-gradle-publish/pull/39#discussion_r4117000413
##########
plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy:
##########
@@ -137,89 +171,127 @@ The credentials and connection url must be specified as
a project property or an
When using `NEXUS_PUBLISH`, either the property `signing.secretKeyRingFile`
must be set to the path of the GPG keyring file or local gpg must be configured
to sign artifacts.
-Note: if project properties are used, the properties must be defined prior to
applying this plugin.
+Note: properties are read from the root project's gradle.properties, the one
in the Gradle user home, -P or ORG_GRADLE_PROJECT_ environment variables, or
from the project applying this plugin: its own gradle.properties, or its build
script before the plugin is applied. Properties set on parent projects,
including in the gradle.properties of a parent project's directory, are not
read.
"""
}
+ /**
+ * Finds a property set via `ext` on the given project itself, or a Gradle
property.
+ *
+ * The project's own extra properties are checked first, so a value set in
its build script overrides a Gradle property,
+ * as it does with {@link Project#findProperty}. Properties set on parent
projects are deliberately not read: resolving
+ * them implicitly is removed in Gradle 10, and reading them explicitly is
not allowed with Isolated Projects.
+ */
+ @PackageScope
+ static Object findProjectProperty(Project project, String name) {
+ def extraProperties = project.extensions.extraProperties
+ if (extraProperties.has(name)) {
+ return extraProperties.get(name)
+ }
+ project.providers.gradleProperty(name).orNull
+ }
+
+ /**
+ * Finds a publish type property. These fall back to a default when unset,
so a value that is only set on a parent
+ * project, which is no longer read, would silently change where artifacts
are published. Fail the build instead.
+ */
+ private Object findPublishTypeProperty(Project project, String name) {
+ Object value = findProjectProperty(project, name)
+ // with Isolated Projects, parent projects cannot be inspected, and
such builds never relied on reading them
+ if (value == null && !buildFeatures.isolatedProjects.active.get()) {
+ for (Project parent = project.parent; parent != null; parent =
parent.parent) {
+ if (parent.extensions.extraProperties.has(name)) {
+ throw new InvalidUserDataException("The property `${name}`
is set on ${parent} but not on ${project}. " +
+ 'The Grails Publish plugin does not read
properties from parent projects. ' +
+ "Set `${name}` in the root project's
gradle.properties, with -P${name}=..., or on ${project} " +
+ 'itself, in its gradle.properties or in its build
script before applying the plugin.')
+ }
+ }
+ }
+ value
+ }
+
@Override
void apply(Project project) {
- project.rootProject.logger.info("Applying Grails Publish Gradle Plugin
for `${project.name}`...");
+ LOG.info('Applying Grails Publish Gradle Plugin for `{}`...',
project.name)
if (project.extensions.findByName('grailsPublish') == null) {
project.extensions.create('grailsPublish', GrailsPublishExtension)
}
- final String nexusPublishUrl = project.findProperty('nexusPublishUrl')
?: System.getenv('NEXUS_PUBLISH_URL') ?: ''
- final String nexusPublishSnapshotUrl =
project.findProperty('nexusPublishSnapshotUrl') ?:
System.getenv('NEXUS_PUBLISH_SNAPSHOT_URL') ?: ''
- final String nexusPublishUsername =
project.findProperty('nexusPublishUsername') ?:
System.getenv('NEXUS_PUBLISH_USERNAME') ?: ''
- final String nexusPublishPassword =
project.findProperty('nexusPublishPassword') ?:
System.getenv('NEXUS_PUBLISH_PASSWORD') ?: ''
- final String nexusPublishStagingProfileId =
project.findProperty('nexusPublishStagingProfileId') ?:
System.getenv('NEXUS_PUBLISH_STAGING_PROFILE_ID') ?: ''
- final String nexusPublishDescription =
project.findProperty('nexusPublishDescription') ?:
System.getenv('NEXUS_PUBLISH_DESCRIPTION') ?: ''
+ final String nexusPublishUrl = findProjectProperty(project,
'nexusPublishUrl') ?: System.getenv('NEXUS_PUBLISH_URL') ?: ''
+ final String nexusPublishSnapshotUrl = findProjectProperty(project,
'nexusPublishSnapshotUrl') ?: System.getenv('NEXUS_PUBLISH_SNAPSHOT_URL') ?: ''
Review Comment:
Thanks, I agree that failing every build is harsher than it needs to be, so
I changed both:
- 658fe1f reads the Nexus properties inside `if (useNexusPublish)`, before
the Nexus plugin is applied. A `nexusPublishUrl` left on a parent project no
longer fails Maven builds such as `test`, while a Nexus release still fails
before anything reaches oss.sonatype.org. The tests now cover a Maven build
ignoring it, and the two Nexus cases publish through Nexus. The README says the
check applies to builds publishing through Nexus.
- 92ce236 adds "or set the NEXUS_PUBLISH_URL environment variable" (or
`NEXUS_PUBLISH_SNAPSHOT_URL`) to the message for those two properties.
--
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]