Skip to content

Use providers.gradleProperty()#7801

Open
mernstcheckerframework wants to merge 4 commits into
typetools:masterfrom
mernst:gradle-providers-get-property
Open

Use providers.gradleProperty()#7801
mernstcheckerframework wants to merge 4 commits into
typetools:masterfrom
mernst:gradle-providers-get-property

Conversation

@mernstcheckerframework

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

build.gradle now reads jdkTestVersion, useJdk21Compiler, and nullnessAll through providers.gradleProperty() instead of project.getProperties(). jdkTestVersion is parsed when present and otherwise defaults to the current Java major version. useJdk21Compiler now uses a provider-backed default of "false" before boolean conversion. nullnessAll now checks provider presence. gradle-mvn-push.gradle now reads publishing repository URLs and credentials through provider-backed property access with fallback values.

Changes

File Summary
build.gradle Switched JDK and nullness build flag lookups to Gradle Provider APIs.
gradle-mvn-push.gradle Switched publishing repository URL and credential lookups to Gradle Provider APIs.

Related issues: None mentioned.

Related PRs: None mentioned.

Suggested labels: build, gradle

Suggested reviewers: None specified.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81c65b6 and c5b6e53.

📒 Files selected for processing (1)
  • build.gradle

Comment thread build.gradle Outdated
@mernst mernst requested a review from smillst July 5, 2026 22:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c47d74c and 77e2139.

📒 Files selected for processing (1)
  • gradle-mvn-push.gradle

Comment thread gradle-mvn-push.gradle
Comment on lines 13 to 16
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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.gradle

Repository: 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.gradle

Repository: 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
done

Repository: 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:


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.

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.

3 participants