O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

A New CLI for Spring Developer Productivity

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Gradle
Gradle
Carregando em…3
×

Confira estes a seguir

1 de 29 Anúncio

A New CLI for Spring Developer Productivity

Baixar para ler offline

Creating new apps based on company standards is harder than it should be. Furthermore, incrementally adding new features to that project over time is even harder with developers often cut-n-pasting code from various sources to solve the problem at hand. In this talk we introduce a new CLI for Spring developers that will help you accelerate your development all while following best practices and keeping the tooling open for change and extension by individual teams and people.

Creating new apps based on company standards is harder than it should be. Furthermore, incrementally adding new features to that project over time is even harder with developers often cut-n-pasting code from various sources to solve the problem at hand. In this talk we introduce a new CLI for Spring developers that will help you accelerate your development all while following best practices and keeping the tooling open for change and extension by individual teams and people.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Semelhante a A New CLI for Spring Developer Productivity (20)

Mais de VMware Tanzu (20)

Anúncio

Mais recentes (20)

A New CLI for Spring Developer Productivity

  1. 1. │©2022 VMware, Inc. Spring CLI A CLI focused on developer productivity - Mark Pollack - Janne Valkealahti
  2. 2. │©2022 VMware, Inc. ● A Spring developer wants to ○ Create a new web project ○ Later, add single sign on functionality to the project ● Spring OSS Survey indicates that documentation and getting started are the most important areas to improve upon ● Conducted user interviews on ‘how to create app of type x’ using spring.io ○ Folks need some help getting started Example Problem
  3. 3. │©2022 VMware, Inc. A common solution ● Go to start.spring.io and select dependencies ● Code ○ Consult documentation, Stack Overflow, example repos, Baeldung.. ○ Look for some sample code close to what you want to do ○ Spring guides are hard to navigate when you don’t want to follow all the details ● The downsides: ○ Time consuming and error prone ○ Which in-house dependencies to add? ○ Can get stuck in a Google cut-n-paste loop ○ Hard to encapsulate company standards ● There should be a better way…
  4. 4. │©2022 VMware, Inc. Spring CLI ● Takes the knowledge of a Spring expert and makes it generally available ● Not just for initial project creation, but part of your day to day workflow ● Sample workflow ○ spring boot new ○ spring boot add jpa ○ spring controller new --feature person ● Available as a native application on Windows, Mac, Linux and uber-jar
  5. 5. │©2022 VMware, Inc. spring boot new ● Create a new project based off an existing working project ○ A "Plain Old Java Project"* hosted in GitHub or GitLab ● spring boot new ○ By default a simple web application ○ Can optionally specify your own project name, package name, etc. * @SpringBootApplication at root of package hierarchy with no @Beans inside
  6. 6. │©2022 VMware, Inc. spring boot new ● spring boot new jpa ○ The “jpa” is an alias for a GitHub URL ● Projects are registered with the CLI so that a simple name can refer to them ● A Project catalog is a collection of projects that share a common theme ○ Once a catalog is registered with the CLI, all the projects in the catalog become available to use ● Note: you can also specify the URL instead of the name
  7. 7. │©2022 VMware, Inc. Demo: spring boot new
  8. 8. │©2022 VMware, Inc. spring boot add ● The same projects that you use to create a new project can also be added to an existing project ● spring boot add jpa ○ Merges the Maven build file ○ Performs a package refactoring to match current project ○ Adds annotations on the Spring Boot main application class ○ Renames the README.adoc file to README-<project-name-added>.adoc ○ Merge application.yaml and application.properties files
  9. 9. │©2022 VMware, Inc. Examples: spring boot add ● spring boot add scheduling ○ Add sample code with @Scheduled annotation ○ Adds test code ○ Add spring-boot starter, awaitility ○ Adds @EnableScheduling annotation to main boot class ● spring boot add feature ○ Add code for ■ Spring Data JPA, @Controller, @Service and @Repository in addition to tests
  10. 10. │©2022 VMware, Inc. Demo: spring boot add
  11. 11. │©2022 VMware, Inc. User-defined commands ● Using an existing “Plain Old Java Project” is not always the best approach ● User-defined commands are defined declaratively ○ Integrated into the CLI ○ Live side by side with your code ○ Help you perform everyday tasks on your current project ○ Based off a templating engine of your choice ■ Handlebars and mustache for now ● Examples ○ Creating a new controller with tests ○ Adding test-container support based on project dependencies ■ In the spirit of “Auto-configuration”, but for code generation ○ Creating configuration files for your platform of choice, CI system, etc…
  12. 12. │©2022 VMware, Inc. User-defined Commands ● Consist of ○ Command name ○ Sub-command name ○ Options file ■ What options does the command take, default values, etc. ○ Action file contains ■ What action to perform on the code base ● Generate a new file ● Inject into an existing file ○ Code, maven dependencies, … ● Execute an arbitrary program ■ Template text ■ Conditional SpEL expression determines if the action is executed
  13. 13. │©2022 VMware, Inc. Creating user-defined commands ● Defined using directory structure convention ○ .spring/commands/<command>/<sub-command> ● Inside that directory ○ Optional command.yaml ○ Action file ■ No special name ■ Based on contents having a front matter section
  14. 14. │©2022 VMware, Inc. .spring/commands/hello/new/command.yml command: description: Generate hello with greeting in a file options: # - name: greeting description: what word to use to say hello dataType: string defaultValue: Hello inputType: text # TEXT
  15. 15. │©2022 VMware, Inc. .spring/commands/hello/new/hello.txt --- action: generate: hello.txt --- Hello {{greeting}} at {{now}} on {{os-name}}.
  16. 16. │©2022 VMware, Inc. Executing a user-defined command $ spring hello new $ cat hello.txt Hello World at Tue Jun 07 18:25:02 EDT 2022
  17. 17. │©2022 VMware, Inc. Template Model ● The model exposed to the template engine has many useful variables ○ All command option names ○ project-root ○ project-name ○ artifact-name ○ os-name ○ maven model and easy access to the most common, eg artifactId
  18. 18. │©2022 VMware, Inc. Demo: User Defined Commands
  19. 19. │©2022 VMware, Inc. Action Files --- action: generate: inject: exec: injectMavenDependency: injectMavenPlugin: injectProperties: engine: mustache conditional: onDependency: --- << Template text goes here >>
  20. 20. │©2022 VMware, Inc. Other features ● Spring Initializr client with Q/A ● GitHub authentication ○ Important due to rate-limiting! ● Configuration enabling setting of default values ○ Instead of “spring boot new –packageName=com.xkcd” ○ “config set boot new packageName com.xkcd” ○ “spring boot new” - now uses com.xkcd as the default package
  21. 21. │©2022 VMware, Inc. Spring Shell Enhancements ● New built in interactive user question flow ○ Example: spring initializr ● Colors! ● Fluent API to define commands ● Command logic can be implemented as a Function or Consumer ● Many other improvements ● See https://spring.io/blog/2022/05/30/spring-shell-2-1-0-m4-is-now-available
  22. 22. │©2022 VMware, Inc. Future areas ● Incorporate the Spring Boot migrator project into the CLI ○ spring boot upgrade ● Refinements around the user-defined commands ○ Execute open-rewrite recipes ○ SpEL conditional execution expressions ● Gradle support ● Multi-module ● Import .spring/config command ● bitbucket
  23. 23. │©2022 VMware, Inc. Wrapping up ● A goal of the Spring CLI is for a collection of curated projects and user-provided commands to emerge in a company. ● The Spring CLI project offers many examples of projects and user-provided commands to help you get started. ● Hope to get feedback and contributions to tackle new important areas ○ spring add graphql ○ spring add native ○ spring test-containers add ○ … ● Not yet a milestone release, aiming for a few weeks
  24. 24. │©2022 VMware, Inc. Where to get it ● https://github.com/spring-projects-experimental/spring-cli ● https://spring-projects-experimental.github.io/spring-cli/spring-cli/
  25. 25. │©2022 VMware, Inc. Thank You!
  26. 26. │©2022 VMware, Inc. Appendix Slides
  27. 27. │©2022 VMware, Inc. Cities Chicago New York Seattle Atlanta Toronto Amsterdam
  28. 28. │©2022 VMware, Inc. City Stamps Chicago New York Seattle Atlanta Toronto Amsterdam
  29. 29. │©2022 VMware, Inc. Logos

×