cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to learn groovy?

Robert_d_Hoedt
Explorer
2,985

Hi,

With Integration Suite comes the option to create groovy scripts.

I have created a few simple scripts by now, mainly by looking at examples and lots of trial and error.

But i would like to learn it better in a more structured way.

So i would i like to know if there are recommended books, or websites that will provide with a good start for groovy?

And maybe also what are recommended tools to use, like what is good editor, or easy to use tools for trying out the code i create.?

Kr

Robert

View Entire Topic
vadimklimov
Active Contributor

Hello Robert,

I would echo what Morten and Daniel have already recommended. Let me add a few tips that I found helpful throughout my learning journey of Groovy when put in the context of SAP Cloud Integration.

  • Learn the Groovy programming language syntax. This is essential, and if you have any prior knowledge of Java or Kotlin, learning Groovy will be easier. Morten has already mentioned a really useful book Groovy in Action. You may also want to check the Groovy language specification here.
  • Learn idiomatic Groovy patterns and style guides. This is not required from day one, but over time, you may find it convenient to write Groovy scripts using some Groovy-native idiomatic patterns, this leads the source code to become more concise and expressive. A good reference documentation on this can be found here.
  • Get familiar with the main Groovy modules that are commonly used in Groovy scripts in SAP Cloud Integration. For example, very commonly, it will be required to parse, transform and produce XML and JSON documents (XML- or JSON-formatted message payloads) - hence, you may want to check relevant documentation, such as here (XML processing) and here (JSON processing). Over time, this will become extended with other - both Groovy SDK and 3rd party - modules that you will be using in your scripts, depending on particular requirements. Those may include the use of modules for other character or binary data formats processing, template engines, security libraries, and so on.
  • The more you progress with scripting in SAP Cloud Integration, the more it is likely that you will need to learn some parts of an Apache Camel framework that SAP Cloud Integration is based on, to help you interact with the framework more effectively from within the developed scripts. I found the book Camel in Action very useful for this, and the official documentation is also very detailed and useful for learning. The overall knowledge of the Camel framework is beneficial when working with SAP Cloud Integration in many other aspects, not only when developing scripts. Be mindful about the version of Apache Groovy - SAP Cloud Integration doesn't use the latest one (currently it uses Camel 2 and will be upgraded to Camel 3 soon).
  • You can also find it useful to get familiar with examples of Groovy code snippets that SAP published for different typical use cases in SAP Help documentation for SAP Cloud Integration here.
  • As the next step, you may find yourself in need of optimizing the developed scripts so that they are more robust and mindful of resource consumption (such as CPU and memory utilization). Here, common practices that are relevant to any other JVM-based programming languages, can be considered and applied when developing Groovy scripts. Be mindful about the version of Java - SAP Cloud Integration uses Java 8 currently.
  • Further, you may want to consider testing aspects of scripts. This is not what you may need to focus on from day one, but you will find the practice of composing tests that can ensure that the developed scripts behave according to expectations, useful when working on larger scripts. It is a helpful habit to consider test cases when you develop the script or even before you start developing the script if we aim adoption of test-driven development practices. Here you can use frameworks that are well-known in the Java community (JUnit, TestNG), or leverage a more tailored framework that is adopted in the Groovy community - Spock. My personal preference here is Spock.

You may find a lot of printed books and digital content on the above topics - some (just a very few) links that I provided are really starting points. As it has already been mentioned by Dhruvin, you may also check an SAP PRESS E-Bite Developing Groovy Scripts for SAP Cloud Platform Integration here which I had the pleasure and honour to co-author with Eng Swee Yeoh and where we tried to cover both basics of Groovy programming language and its application to some common use cases and scenarios in the context of SAP Cloud Integration.

As for tooling, as Morten has already suggested, the choice of a code editor / IDE is subjective - if you already use a general-purpose code editor / IDE, you may try extending its use to Groovy development activities, too (assuming it either has native support for Groovy or can be extended with a relevant plugin/extension). For Groovy development, I personally prefer to use IntelliJ IDEA, but some advanced code editors (such as VS Code) and IDEs (such as Eclipse) can be used for Groovy development, too.

Morten has already suggested getting Groovy installed on your machine locally so that it becomes more convenient to develop and run Groovy code snippets. I would definitely support this recommendation. As a more advanced option, you can then use dev containers (such as described here for VS Code). This will help keep your developer machine lean and clean, but this will require Docker installed on your machine or accessible on the remote host and will require some basic knowledge of Docker (or general containerization), so can be considered for the future as an alternative to installing Groovy runtime locally for a more advanced setup of your development environment.

Regards,

Vadim

MortenWittrock
Active Contributor
0 Kudos

Excellent answer as always, Vadim!