Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gradlew location when trying to location a gradle executable #610

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/sources/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ To run `licensed` for specific projects in a [multi-build project](https://docs.
```yml
apps:
- source_path: ./path/to/subproject
```

### Gradlew

The `gradle.gradlew` property is used to determine where the `gradlew` executable is. The default location the [configuration root](../configuration/configuration_root.md).

```yml
gradle:
- gradlew: path/from/root/to/gradle/gradlew
```
Comment on lines +26 to 33
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ thanks for the docs update!!

Copy link
Contributor

Choose a reason for hiding this comment

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

oh 🤦 the nested gradlew property isn't an array and shouldn't have the - prefix. I'll fix the docs in the release PR

9 changes: 8 additions & 1 deletion lib/licensed/sources/gradle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def executable
return @executable if defined?(@executable)

@executable = begin
gradlew = File.join(config.pwd, "gradlew")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For gradle multi-projects builds, the config.pwd is often a subfolder and not the root of the project.
I think licensed should look for gradlew at the root since it is the official location for the gradle wrapper

What do you think about that ?

return gradlew if File.executable?(gradlew)

"gradle" if Licensed::Shell.tool_available?("gradle")
Expand All @@ -89,6 +88,14 @@ def configurations
end
end

# Returns the path to the Gradle wrapper.
def gradlew
@gradlew ||= begin
gradlew = config.dig("gradle", "gradlew")
config.root.join(gradlew || "gradlew").to_s
end
end

# Returns a key to uniquely identify a name and version in the obtained CSV content
def csv_key(name:, version:)
"#{name}-#{version}"
Expand Down