<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>aaabramov</title>
    <description>Personal knowledge base — notes and interactive explainers.
</description>
    <link>https://blog.iamandrii.com/</link>
    <atom:link href="https://blog.iamandrii.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Wed, 22 Apr 2026 20:12:10 +0000</pubDate>
    <lastBuildDate>Wed, 22 Apr 2026 20:12:10 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Play routes import</title>
        <description>&lt;h2 id=&quot;how-to-add-import-statements-to-routes&quot;&gt;How to add import statements to routes?&lt;/h2&gt;

&lt;p&gt;While using Play Framework you have to describe all your endpoints in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conf/routes&lt;/code&gt; file:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-play2htmlrouting&quot;&gt;# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

GET     /api/v1/people              controllers.PeopleController.add()
GET     /api/v1/people/:personId    controllers.PeopleController.get(personId: java.util.UUID)
POST    /api/v1/people              controllers.PeopleController.create()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, our mission is to bring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;java.util.UUID&lt;/code&gt; into scope of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;routes&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The solution is to edit a bit out &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;build.sbt&lt;/code&gt; file:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-sbtshell&quot;&gt;import play.sbt.routes.RoutesKeys

RoutesKeys.routesImport += &quot;java.util.UUID&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you may know, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;routes&lt;/code&gt; file is compiled by Play Framework sbt plugin into byte code and looks similar to the following:&lt;/p&gt;

&lt;div class=&quot;language-scala highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;_root_.java.util.UUID&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// @LINE:5&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lazy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;com_github_abrasha_v1_controller_PeopleController_route0_route&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;PathPattern&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;StaticPart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StaticPart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;defaultPrefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StaticPart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;api/v1/people&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  
&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lazy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;com_github_abrasha_v1_controller_PeopleController_route0_route_invoker&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;createInvoker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;PeopleController_3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;play&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;routing&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;HandlerDef&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;getClass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;getClassLoader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;people&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;com.github.abrasha.web.v1.controller.PeopleController&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;people&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;prefix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;api/v1/people&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;Seq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yeah, a bit horrible, but really important thing is that there is a desired &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import&lt;/code&gt; statement:&lt;/p&gt;
&lt;div class=&quot;language-scala highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;_root_.java.util.UUID&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It means that we can simplify a bit our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;routes&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-play2htmlrouting&quot;&gt;GET     /api/v1/people              controllers.PeopleController.add()
GET     /api/v1/people/:personId    controllers.PeopleController.get(personId: UUID)
POST    /api/v1/people              controllers.PeopleController.create()
&lt;/code&gt;&lt;/pre&gt;
</description>
        <pubDate>Tue, 07 Nov 2017 20:31:15 +0000</pubDate>
        <link>https://blog.iamandrii.com/posts/play-routes-import/</link>
        <guid isPermaLink="true">https://blog.iamandrii.com/posts/play-routes-import/</guid>
        
        
        <category>playframefork</category>
        
      </item>
    
      <item>
        <title>Groovy strings</title>
        <description>&lt;h2 id=&quot;why-groovy-strings-are-so-awesome&quot;&gt;Why Groovy strings are so awesome?&lt;/h2&gt;

&lt;p&gt;At first, let’s see which types of string are there in Groovy.&lt;/p&gt;

&lt;p&gt;The first type is a plains string. It is a literal surrounded with single quote.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-groovy&quot; data-lang=&quot;groovy&quot;&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;John&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; John&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nothing special about it. Just a boring Java string.&lt;/p&gt;

&lt;p&gt;But the power is actually in Groovy string, a.k.a. &lt;a href=&quot;http://docs.groovy-lang.org/latest/html/api/groovy/lang/GString.html&quot;&gt;GString&lt;/a&gt;. It is a literal that is surrounded with double quotes.&lt;/p&gt;

&lt;p&gt;Let’s start from an example.&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;John&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello, $name&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Hello, John&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can avoid concatenation like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Hello, &quot; + name&lt;/code&gt; in code thankfully to the GStrings.
With such syntax you can substitute not only variable values but also whole expressions:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;John&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello, ${name.toUpperCase()}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Hello, John&lt;br /&gt;
&amp;gt; 2 * 2 = 4&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Be sure that you put curly braces around the expression. Because if you want, you will get result like:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;John&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello, $name.toUpperCase()&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Caught: groovy.lang.MissingPropertyException: No such property: toUpperCase for class: java.lang.String
groovy.lang.MissingPropertyException: No such property: toUpperCase for class: java.lang.String&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For escaping special symbols is GStrings you can put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt; characher before them:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Result of \${20 + 5} = ${20 + 5}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Result of ${20 + 5} = 25&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The third type of string in Groovy is triple single quoted string.
It is also called multi-line string. Its purpose is to store multi-line strings without putting new line characters (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\n&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;An example:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&apos;&apos;Hello team,
have a nice day!

Kind regards,
Mike
&apos;&apos;&apos;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Hello team,&lt;br /&gt;
&amp;gt; have a nice day!&lt;br /&gt;
&amp;gt; &lt;br /&gt;
&amp;gt; Kind regards,&lt;br /&gt;
&amp;gt; Mike&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you need to escape new line symbol just put backslash (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt;) in the end of line:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&apos;&apos;Should be in \
the same line&apos;&apos;&apos;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; Should be in the same line&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are some useful methods injected into strings in Groovy. Thankfully to them, it is so easy to use Groovy as a a scripting language.&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;ls -la&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;&amp;gt; total 20&lt;br /&gt;
&amp;gt; drwxr-xr-x 2 user user 4096 Jan 28 00:13 .&lt;br /&gt;
&amp;gt; drwxr-xr-x 3 user user 4096 Jan 27 23:26 ..&lt;br /&gt;
&amp;gt; -rw-r–r– 1 user user   54 Jan 28 00:12 Example.groovy&lt;/p&gt;
&lt;/blockquote&gt;

</description>
        <pubDate>Mon, 16 Jan 2017 20:21:15 +0000</pubDate>
        <link>https://blog.iamandrii.com/posts/groovy-strings/</link>
        <guid isPermaLink="true">https://blog.iamandrii.com/posts/groovy-strings/</guid>
        
        
        <category>groovy</category>
        
      </item>
    
      <item>
        <title>Creating gradle task</title>
        <description>&lt;h2 id=&quot;how-to-create-custom-task-in-gradle&quot;&gt;How to create custom task in Gradle?&lt;/h2&gt;

&lt;p&gt;Sometimes you need to declare custom tasks in your project.&lt;/p&gt;

&lt;p&gt;For instance, you need to copy all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.log&lt;/code&gt; files from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;files&lt;/code&gt; directory to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_logs_&lt;/code&gt; folder:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;copyLogs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Copy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;logs&apos;&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;// from which directory to copy&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;*.log&apos;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// what patterns to include&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;into&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;archive&apos;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// where to copy these files&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;See: &lt;a href=&quot;https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html&quot;&gt;Copy task type&lt;/a&gt;&lt;br /&gt;
See: &lt;a href=&quot;https://abrasha.github.io/groovy/2017/01/16/groovy-strings.html&quot;&gt;Groovy strings guide&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-to-declare-tasks-chain&quot;&gt;How to declare tasks chain?&lt;/h2&gt;

&lt;p&gt;What if you need to zip them afterwards?
To follow the declarative style of Gradle you would better create chain of tasks rather that creating one but complex.
Logically the steps are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Zip all log files&lt;/li&gt;
  &lt;li&gt;Move it to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;archive&lt;/code&gt; directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let’s define corresponding zip task:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zipLogs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Zip&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// tell that we should copy the logs at first&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dependsOn&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;copyLogs&apos;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// setting archive name using GString enhancement&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;archiveName&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;logs-${LocalDateTime.now()}.zip&quot;&lt;/span&gt; 

    &lt;span class=&quot;c1&quot;&gt;// from what directory collect the files&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;logs&apos;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// filter closure&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endsWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;log&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// where to put the result archive&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;destinationDir&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;archive&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Read more about GString: &lt;a href=&quot;http://docs.groovy-lang.org/latest/html/documentation/#_double_quoted_string&quot;&gt;GString documentation&lt;/a&gt;&lt;br /&gt;
Read more about Groovy closure: &lt;a href=&quot;http://groovy-lang.org/closures.html&quot;&gt;Groovy closure&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this way can call these tasks separately but tasks are logically separated and in the same time they are chained.&lt;/p&gt;

&lt;p&gt;In this way, you can create new task, e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishLogs&lt;/code&gt; and say that it &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dependsOn&lt;/code&gt; zipping the files and just operate the state after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zipLogs&lt;/code&gt; task.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;publishLogs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;dependsOn:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;zipLogs&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doLast&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// publish the logs or send them via e-mail&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Mon, 16 Jan 2017 20:21:15 +0000</pubDate>
        <link>https://blog.iamandrii.com/posts/creating-gradle-task/</link>
        <guid isPermaLink="true">https://blog.iamandrii.com/posts/creating-gradle-task/</guid>
        
        
        <category>gradle</category>
        
      </item>
    
  </channel>
</rss>
