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

Support adding dependencies to an existing Ktor project #44

Merged
merged 23 commits into from
Feb 5, 2025

Conversation

Stexxe
Copy link
Contributor

@Stexxe Stexxe commented Jan 31, 2025

https://youtrack.jetbrains.com/issue/KTOR-7749

The PR seems huge, but it's not. Most of the files are generated by ANTLR or are part of the test projects.

This PR adds the add command, which can be used to add Ktor dependencies to a Gradle project.
The usage instructions can be found in the README.md.

How it works

  1. It searches for the Ktor version in the build.gradle.kts and version catalog files.
  2. If the version cannot be found, it uses the default version from the /project/settings endpoint.
  3. Then, it requests the artifacts/{version}/search endpoint to search for the Ktor artifacts by a given name.
  4. If the name is ambiguous or the module isn't found, it prints an error message.
  5. It parses the build.gradle.kts and the version catalog files (if it exists).
  6. It checks if the dependency is already included to avoid inserting the duplicate.
  7. It adds the dependency to the files based on the way the other Ktor dependencies are defined.
  8. If the Ktor module requires the serialization plugin, it adds the plugin too.
  9. Finally, it presents the user with a diff of the suggested changes and asks them if the changes should be applied.
  10. Before applying the changes, the files required changes are backed up in memory to avoid partial patches.

Stexxe added 20 commits January 21, 2025 14:22
…shells

Use group/name and module attributes based on existing Ktor dependencies
Small fixes
Accept variable number of modules to add
Allow adding client dependencies and refactoring
Extract into function getting the TOML catalog path
Refactor checking if dependency is already exist
Add a Ktor dependency to a list where versions stored in Kotlin variables
Check if Ktor dep with version variable does already exist
Consider platform suffixes of other Ktor dependencies
Use the same variable reference for the dependency if any dependencies have version got by a delegate
Print messages about not supported Maven and Groovy DSL projects
Print a message that adding dependency to a KMP project isn't supported
Print info messages when configuration isn't supported for adding a Ktor dependency
Print friendly message to file a bug on panicking
Add prompt to ask if changes should be applied to apply the changes
Add a case when no dependencies in build and no libraries in toml
Look for serialization plugin with full ID
Add Ktor dependency with a proper suffix taken from other Ktor dependencies
Add raw Ktor test dependency
Add raw Ktor dependency when Ktor Gradle plugin is defined
Fix parsing Gradle files without a new line at EOF
Check if serialization plugin is already defined
Add serialization plugin when a dependency requires it
Refactor TOML parsing
Refactor Kotlin parsing
WIP
Add a Ktor dependency when no other dependencies and no catalog file
Check if a hardcoded dependency is present with BOM
Fix the BOM test and distinguish Ktor shared dependencies
Add dependency for case when BOM is present
Check if the given Ktor dependency is already defined
Add a case when no Ktor versions in the toml file
Add a case when versions file doesn't contain any Ktor dependencies
Add shared dependencies and improve finding by edit distance
Test adding dependencies and add a simple scenario
Use MavenCoords struct
KTOR-7749 Find Ktor maven coordinates by module name or an associated symbol
KTOR-7749 Add basic implementation for adding a Ktor dependency into version catalog
@Stexxe Stexxe requested a review from vnikolova January 31, 2025 12:55
@Stexxe Stexxe requested a review from bjhham February 3, 2025 08:23
@bjhham
Copy link

bjhham commented Feb 3, 2025

Could you add a few screenshots here? I'm curious to see what the diff looks like etc.

Copy link

@bjhham bjhham left a comment

Choose a reason for hiding this comment

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

Very cool 👍

cmd/ktor/main.go Show resolved Hide resolved
cmd/ktor/main.go Show resolved Hide resolved
Copy link

@vnikolova vnikolova left a comment

Choose a reason for hiding this comment

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

Looks good! Some small adjustments to the texts below.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
@Stexxe Stexxe requested review from vnikolova and bjhham February 4, 2025 11:48
@Stexxe Stexxe merged commit 11c0261 into main Feb 5, 2025
@Stexxe Stexxe deleted the stexxe/add-deps-command branch February 5, 2025 08:22
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