Skip to content

Commit c35d661

Browse files
authored
Improve detection error message with better user experience (#168)
1 parent eb81376 commit c35d661

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1414

1515
- Framework detection now uses Gradle dependency resolution instead of build file parsing for more reliable detection across all DSL syntax, version catalogs, and dependency sources. ([#165](https://github.com/heroku/heroku-buildpack-gradle/pull/165))
1616
- Improved error messages with detailed troubleshooting steps, documentation links, and local reproduction guidance. ([#165](https://github.com/heroku/heroku-buildpack-gradle/pull/165))
17+
- Improve detection error message with better user experience and guidance for other build tools. ([#168](https://github.com/heroku/heroku-buildpack-gradle/pull/168))
1718

1819
### Removed
1920

bin/detect

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -euo pipefail
44

55
BUILD_DIR="${1}"
66

7+
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
8+
9+
source "${BUILDPACK_DIR}/lib/output.sh"
10+
711
gradle_files=(
812
"gradlew"
913
"build.gradle"
@@ -23,5 +27,33 @@ for gradle_file in "${gradle_files[@]}"; do
2327
fi
2428
done
2529

26-
(>&2 echo "Could not find a gradlew file or other supported Gradle files!")
30+
output::error <<-EOF
31+
Error: Your app is configured to use the Gradle buildpack,
32+
but we couldn't find any supported Gradle project files.
33+
34+
The Gradle buildpack requires at least one of the following files
35+
in the root directory of your source code:
36+
37+
Supported Gradle files: $(printf "%s, " "${gradle_files[@]}" | sed 's/, $//')
38+
39+
IMPORTANT: If your project uses a different build tool:
40+
- For Maven projects, use the heroku/java buildpack instead
41+
- For sbt projects, use the heroku/scala buildpack instead
42+
43+
Currently the root directory of your app contains:
44+
45+
$(ls -1A --indicator-style=slash "${BUILD_DIR}" 2>/dev/null || echo "Unable to list directory contents")
46+
47+
If your app already has Gradle files, check that they:
48+
49+
1. Are in the top level directory (not a subdirectory).
50+
2. Have the correct spelling (the filenames are case-sensitive).
51+
3. Aren't listed in '.gitignore' or '.slugignore'.
52+
4. Have been added to the Git repository using 'git add --all'
53+
and then committed using 'git commit'.
54+
55+
For help with using Gradle on Heroku, see:
56+
https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
57+
EOF
58+
2759
exit 1

test/spec/detection_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'spec_helper'
4+
5+
RSpec.describe 'Gradle buildpack detection' do
6+
it 'shows helpful error message when no Gradle project files are found' do
7+
app = Hatchet::Runner.new('non-gradle-app', allow_failure: true)
8+
app.deploy do
9+
expect(clean_output(app.output)).to include(<<~OUTPUT)
10+
remote: ! Error: Your app is configured to use the Gradle buildpack,
11+
remote: ! but we couldn't find any supported Gradle project files.
12+
remote: !
13+
remote: ! The Gradle buildpack requires at least one of the following files
14+
remote: ! in the root directory of your source code:
15+
remote: !
16+
remote: ! Supported Gradle files: gradlew, build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts
17+
remote: !
18+
remote: ! IMPORTANT: If your project uses a different build tool:
19+
remote: ! - For Maven projects, use the heroku/java buildpack instead
20+
remote: ! - For sbt projects, use the heroku/scala buildpack instead
21+
remote: !
22+
remote: ! Currently the root directory of your app contains:
23+
remote: !
24+
remote: ! README.md
25+
remote: !
26+
remote: ! If your app already has Gradle files, check that they:
27+
remote: !
28+
remote: ! 1. Are in the top level directory (not a subdirectory).
29+
remote: ! 2. Have the correct spelling (the filenames are case-sensitive).
30+
remote: ! 3. Aren't listed in '.gitignore' or '.slugignore'.
31+
remote: ! 4. Have been added to the Git repository using 'git add --all'
32+
remote: ! and then committed using 'git commit'.
33+
remote: !
34+
remote: ! For help with using Gradle on Heroku, see:
35+
remote: ! https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
36+
OUTPUT
37+
end
38+
end
39+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Not a Gradle App
2+
3+
This directory contains no Gradle project files to test detection failure.

0 commit comments

Comments
 (0)