Bonjour to all Gradle users… but especially for An...
# feed
j
Bonjour to all Gradle users… but especially for Android devs who have been taught to “_configure your build_”. You are missing out if you see Gradle as something you configure, but instead of using XML like Maven, you use strange
someBlock { ... }
The mindset shift : You don’t configure Gradle, you program it! … in Kotlin of course Learning to program your build takes time initially, but much better than countless spending hours debugging your build if you don’t learn Gradle https://blog.kotlin-academy.com/weeks-of-debugging-your-build-can-save-you-hours-of-learning-gradle-348de387c12c
It has been a while that I published a Kotlin-related article. Thanks to @marcinmoskala and Kt Academy cc @dwursteisen who might be interested
❤️ 1
c
I found all build tools annoying at some point. But Gradle is certainly not the worst. I found the discoverability of programming Gradle improved a lot by using Kotlin over Gradle with IntelliJ. Code completion and error hints help a lot!
👍 1
I came up with this littel programmed Gradle nugget that helps out team understand what Gradle actually does:
image.png
👍 2
j
@Cies yes, Kotlin was the missing piece of the puzzle.
What happened is that the dynamic nature of Groovy combined badly with all the meta-programming done in Gradle to give us poor tooling support.
https://dev.to/jmfayard/how-kotlin-makes-editing-your-gradle-build-less-frustrating-232l
@Cies can you share a gist of your snippet for easier copy/pasting?
c
@jmfayard yes, java is simply to verbose for this type of tasks, groovy lacks IDE help/ type safety, scala/SBT has too much noise. i have webpack configs (in JS) probably for the same reasons I did not like Groovy. I think I prefer only one build system over Gradle at this point, namely: https://shakebuild.com/manual (a bit more noisy syntax, but that's also a Haskeller's preference I guess)
1
j
tried it, it just works are you using that as a way to demonstrate Gradle programming? or to help people understand the usage I find the Gradle build scan incredibly useful https://scans.gradle.com/s/qz2hzc5zx6pka/timeline?details=2ltkkn6ypxfns
c
scan helps, but it is often more than asked for
also it needs more work (upload/download)
i just want my co-devs to see how Gradle plans it's tasks
👍 1
BTW: it works, but not correctly in all cases. not sure what the problems were, but sometimes it does nto show things correctly
j
that’s also a good example to understand how to program Gradle to do whatever custom thing you want
you can’t do that in XML
c
i tried to program gradle to do some file linking for me, but I gave up
really, really hard
j
yes, one shouldn’t do hard things in the
build.gradle.kts
file either. The idea is to write a Gradle plugin in Kotlin and then configure it simply in
build.gradle.kts
split the WHAT and the HOW
c
many people have been programming many hours in XML for some weird fetishistic reason (i suppose), see XSLT for example. 🤣
j
never mentino XSLT without “Content warning” 😛
c
@jmfayard Maven forces one to split what and how, Gradle allows me to first start with a few lines of kotlin in the
build.gradle.kts
and the move it to a plugin when time comes
i find it really hard to "just get a list of files" from some glob file selector in Gradle
also linking is even hard for Java i found out
we also have a Makefile for things that would be hard in Gradle (docker stuff, pushing to the container repo, etc.), so I put the linking in there in a few lines of easy to grasp code:
Copy code
relink-views-js-to-public: ## Relink all JS files in app/views to public/scripts/template
        @set -e; \
        rm -rf public/scripts/template; \
        mkdir public/scripts/template; \
        echo "Emptied APP_ROOT/public/scripts/template"; \
        for f in $$(find app/views -type f -name "*.js"); do \
          link_target=public/scripts/template/$$(echo $$f | cut -d'/' -f3-); \
          mkdir -p $$(dirname $$link_target); \
          echo "Hard linked $$f -> $$link_target"; \
          ln $$f $$link_target; \
        done
(and the Makefile should be a Justfile, as we do not use make as a build tool since we have... gradle!)