Use providers.gradleProperty()#7801
Conversation
📝 WalkthroughWalkthrough
Changes
Related issues: None mentioned. Related PRs: None mentioned. Suggested labels: build, gradle Suggested reviewers: None specified. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@build.gradle`:
- Line 57: The jdk21Compiler flag is being assigned from
providers.gradleProperty("useJdk21Compiler") without converting the string value
to a boolean, so false-like inputs still behave as truthy. Update the
jdk21Compiler assignment in build.gradle to parse the provider value with
toBoolean() before applying the default fallback, so the selection logic used by
the JDK 21 compiler path reflects the actual boolean intent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: eff58a92-a866-46e7-8f3a-2d0b63b0f346
📒 Files selected for processing (1)
build.gradle
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@gradle-mvn-push.gradle`:
- Around line 13-16: The Maven publish credentials setup currently uses
providers.gradleProperty(...).orNull in the credentials block, which can leave
username and password unset and cause a late, opaque publish failure. Update the
publishing configuration in gradle-mvn-push.gradle to validate
SONATYPE_NEXUS_USERNAME and SONATYPE_NEXUS_PASSWORD before the credentials block
is used, and fail fast with a clear missing-credentials message for local
publish runs. Use the existing publishing/credentials configuration as the
insertion point so the check happens before maven-publish tries to authenticate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 96c1730d-1325-4172-9df2-0fb40e1f3f96
📒 Files selected for processing (1)
gradle-mvn-push.gradle
| credentials { | ||
| username = project.properties.get("SONATYPE_NEXUS_USERNAME") | ||
| password = project.properties.get("SONATYPE_NEXUS_PASSWORD") | ||
| username = providers.gradleProperty("SONATYPE_NEXUS_USERNAME").orNull | ||
| password = providers.gradleProperty("SONATYPE_NEXUS_PASSWORD").orNull | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check other places where SONATYPE_NEXUS_USERNAME/PASSWORD or this repo block are referenced
rg -n 'SONATYPE_NEXUS_(USERNAME|PASSWORD)' --type=groovy
rg -n 'publish' gradle-mvn-push.gradleRepository: typetools/checker-framework
Length of output: 165
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- gradle-mvn-push.gradle outline ---'
ast-grep outline gradle-mvn-push.gradle --view expanded || true
echo
echo '--- gradle-mvn-push.gradle lines 1-120 ---'
nl -ba gradle-mvn-push.gradle | sed -n '1,120p'
echo
echo '--- build.gradle credential/publish snippets ---'
rg -n -C 3 'SONATYPE_NEXUS_(USERNAME|PASSWORD)|maven|publishing|publish' build.gradle gradle-mvn-push.gradleRepository: typetools/checker-framework
Length of output: 302
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- gradle-related files ---'
git ls-files '*gradle*' | sed -n '1,200p'
echo
echo '--- locate gradle-mvn-push.gradle ---'
fd -a 'gradle-mvn-push.gradle' . || true
echo
echo '--- read candidate files with line numbers ---'
for f in $(git ls-files '*gradle*' | grep -E '(^|/)(gradle-mvn-push\.gradle|build\.gradle)$'); do
echo "### $f"
cat -n "$f" | sed -n '1,160p'
echo
doneRepository: typetools/checker-framework
Length of output: 50383
🌐 Web query:
Gradle maven-publish credentials username password null NullPointerException publish missing credentials
💡 Result:
A NullPointerException (NPE) or "Username must not be null" error during Gradle publishing typically occurs when the maven-publish plugin expects credentials for a repository but receives a null value for the username or password [1][2][3]. This error usually happens because the credentials are being resolved at configuration time, or the variables used to provide them (e.g., via findProperty or System.getenv) are missing or incorrectly configured [4][3][5]. To resolve or avoid this issue, follow these best practices: 1. Ensure properties are correctly named and defined: Verify that the properties you are accessing exist in your gradle.properties file, ~/.gradle/gradle.properties, or as environment variables [6][3]. A common mistake is a mismatch between the property name in the build script and the name provided in the property file [3]. 2. Use secure credential management: Avoid hardcoding credentials in build scripts [6]. Instead, use external properties or environment variables [6][7]: credentials { username = project.findProperty("myRepoUsername")?: System.getenv("MY_REPO_USERNAME") password = project.findProperty("myRepoPassword")?: System.getenv("MY_REPO_PASSWORD") } 3. Debugging with Gradle Scan: If the error persists and is non-obvious, run your build with the --scan flag. This often reveals more detailed stack traces that can pinpoint exactly which part of the credential resolution is failing [1]. 4. Check for incompatible configurations: If you are using features like the Configuration Cache, ensure your credential handling is compatible [4]. In some cases, explicitly defining credentials that are not needed for certain tasks can cause issues; ensure you are only triggering publication tasks when credentials are actually available [6][5]. 5. Report misconfiguration: If you encounter an NPE rather than a helpful error message (like "Username must not be null"), it is often considered a bug in the plugin's error handling [1][2]. Double-check that you are not accidentally setting credentials on a repository type that does not support them (e.g., some authentication methods do not use standard username/password credentials) [2].
Citations:
- 1: Gradle does not give an obvious error message when Maven credentials for maven-publish are null gradle/gradle#6369
- 2: https://discuss.gradle.org/t/gradle-publish-gives-java-lang-nullpointerexception-error/51554
- 3: https://stackoverflow.com/questions/63881149/initially-publishing-a-github-package-shows-username-must-not-be-null
- 4: PasswordCredentials are incompatible with configuration cache gradle/gradle#23979
- 5: https://stackoverflow.com/questions/62949863/how-to-read-maven-repository-credentials-only-when-needed
- 6: https://docs.gradle.org/9.2.0/samples/sample_publishing_credentials.html
- 7: https://github.com/github/docs/blob/main/content/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry.md
Guard against null Sonatype credentials
orNull leaves username/password unset when the properties are missing, and maven-publish can fail at publish time with an opaque NPE or “Username must not be null” instead of a clear missing-credentials error. Add an explicit check or fail-fast message for local publish runs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@gradle-mvn-push.gradle` around lines 13 - 16, The Maven publish credentials
setup currently uses providers.gradleProperty(...).orNull in the credentials
block, which can leave username and password unset and cause a late, opaque
publish failure. Update the publishing configuration in gradle-mvn-push.gradle
to validate SONATYPE_NEXUS_USERNAME and SONATYPE_NEXUS_PASSWORD before the
credentials block is used, and fail fast with a clear missing-credentials
message for local publish runs. Use the existing publishing/credentials
configuration as the insertion point so the check happens before maven-publish
tries to authenticate.
No description provided.