Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaとGroovyで書かれたGradleプラグインをKotlinで書き直した話 / Con...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kengo TODA
October 26, 2023
Programming
1.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaとGroovyで書かれたGradleプラグインをKotlinで書き直した話 / Converted a Gradle plugin from Groovy&Java to Kotlin
2023/Oct/26 集まれKotlin好き!Kotlin愛好会 vol.47 で発表したものです。
Kengo TODA
October 26, 2023
More Decks by Kengo TODA
See All by Kengo TODA
セキュリティ担当がいない中小医療機関を院外のRISSはどう支えるべきか / How External RISS Can Help Small Medical Institutions
eller86
1
240
AI といっしょに仕事をする(子供向け)
eller86
0
56
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
210
生成AI 業務応用向けガイドライン 斜め読み / Overview of Generative AI Business Application Guidelines
eller86
0
230
KotlinユーザのためのJSpecify入門 / JSpecify 101 for Kotlin Devs
eller86
0
2.4k
ヒューマンスキル / The Humanskills
eller86
0
790
医療機関向けシステムの信頼性 / Reliability of systems for medical institutions
eller86
0
560
Server-side Kotlinを使うスタートアップでどんなDetektルールが育ったか / Detekt rules made in start-up working with Server-side Kotlin
eller86
0
1.7k
Java開発者向けのKotlin Gradleビルドスクリプト入門 / Gradle Build Script in Kotlin 101
eller86
1
2.3k
Other Decks in Programming
See All in Programming
Jetpack Compose Mechanisms
skydoves
3
880
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
280
AI-Powered Domain-Driven Design
ziobrando
0
340
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
260
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
AmebaブログはKMPから卒業します
kmars0605
0
280
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
12
10k
JIS keyboard support in Omarchy
lef237
0
160
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
3
1.3k
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
460
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
150
Featured
See All Featured
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
960
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
470
ラッコキーワード サービス紹介資料
rakko
5
5.5M
Leo the Paperboy
mayatellez
10
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Six Lessons from altMBA
skipperchong
29
4.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
Technical Leadership for Architectural Decision Making
baasie
3
620
The Mindset for Success: Future Career Progression
greggifford
PRO
0
550
Transcript
JavaとGroovyで書かれた Gradleプラグインを Kotlinで書き直した話 2023/Oct/26 集まれKotlin好き!Kotlin愛好会 vol.47 Kengo TODA
#LOVE_KOTLIN 自己紹介 フリーソフトウェア開発出身。OSSエンジニアやBtoB研究開発を経て、現在は 医療機関向けにウェブサービスを提供する株式会社ヘンリーでSREやCorporate Engineerを担当。元SpotBugsの中の人。 ChatGPTと一緒に数学書とか論文とかを読むのが最近のマイブーム。 https://twitter.com/Kengo_TODA https://github.com/KengoTODA 2
#LOVE_KOTLIN 今日話すこと JavaとGroovyで書いてあった spotbugs-gradle-plugin をKotlinで書き直してRC版リ リースまで漕ぎつけたので、所感を共有します! 3
#LOVE_KOTLIN Agenda 1. JavaとGroovyで書いて課題だと感じていたこと 2. Kotlinの流れがきた! 3. 書き換えプロセスの体験 4. Kotlinで書いて良かったところ
4
#LOVE_KOTLIN JavaとGroovyで書いて課題だと感じていたこと - null-safetyがない、アノテーションでの補完は漏れが生じる - Groovyにtype-safety がない、IDEによる補完が効かないことがある - Gradleの文書がKotlinとGroovyを前提にしていて、Javaで書きにくい -
周りにGroovyを書いているひとがいなくなった - 昔はJenkinsfileでけっこう書かれていた( 2016年〜) - GradleのGroovy対応がv3に留まっている - 2022年からv4を検証してるけどGradle 8.0から9.0に対応を延期したので優先度高くなさそう 5
#LOVE_KOTLIN Kotlinの流れがきた! - 2022年、自分がサーバサイドKotlinを書いてる企業に転職した - 周りにKotlinを書いているひとが多い環境になった - 2023年、GradleがKotlinをDSLの標準言語にした - 以前「Java開発者向けのKotlin
Gradleビルドスクリプト入門 」を話したのでご参考まで - Gradleが提供するドキュメントも多い - 何なら公式プラグインも Kotlinで書かれていたりする - Kotlinなら型安全、null安全、強力なIDEの支援などが一気に解決される 6
#LOVE_KOTLIN Javaからの書き換え 簡単だったので語るべきところがない - IntelliJ IDEAがJava→Kotlinの変換をだいたいやってくれる - IntelliJ IDEAがKotlinらしい書き方のサジェストもしてくれる -
だいたいIntelliJ IDEAに任せておけば間違いない - フォーマットもSpotless(ktlint)にお任せ 7
#LOVE_KOTLIN Groovyからの書き換え 面倒だったところ - IntelliJ IDEAが変換をやってくれないので自分でやる - コンストラクタ、メソッド、フィールドなど細かいところで書き方が違う 良かったところ -
lateinit相当のフィールドの存在に気づけた - コンストラクタでfinalではないメソッドを呼び出していたことに気づけた 8
#LOVE_KOTLIN 難しかったところ • functional testをSpockからKotestに切り替えたかったが、テストが起動しな かったので諦めた 9
workerExecutor.submit(SpotBugsRunne r.class, config -> { // getFirstEnabled() がnullable config.params(spec, getIgnoreFailures(),
reports.getFirstEnabled().getDestin ation()); 事例 Gradleプラグインにおけるnull-safetyの必要性 「解析レポート出力先」をファイルパスと形式( txt, xml, html, ...)をセットで設定できる仕様だった。 レポートがひとつも設定されていない場合に NPEを 投げてしまった。対象メソッドには @Nullableアノ テーションがついていたが、リリースされるまでこの 問題に気づけなかった。 https://github.com/spotbugs/spotbugs-gradle-p lugin/issues/68 10
#LOVE_KOTLIN Kotlinで書いて良かったところ scope functionで初期化コードを意味ある単位で まとめて書ける 11 var extension = project.extensions.create(
“extensionName”, MyExtension.class ).apply { prop.convention(true) another.convention(“default”) }
private FileCollection classes; void setClasses(FileCollection fileCollection) { this.classes = fileCollection
} FileCollection getClasses() { if (classes == null) { if (getClassDirs() == null) { throw new InvalidUserDataException("The classDirs property is not set") } return getClassDirs().asFileTree.filter({ File file -> file.name.endsWith(".class") }) } else { return classes } } Kotlinで書いて良かったところ フィールドの記述が短くできた 12 var classes: FileCollection? = null get() { return field ?: ( classDirs.asFileTree.filter { it.name.endsWith(".class") } ) }
#LOVE_KOTLIN ご清聴ありがとうございました Javaもまだ使ってるよ!という方は、今回紹介したspotbugs-gradle-pluginのv6を試 してほしいですm (_ _)m 13
#LOVE_KOTLIN 補足 なぜJavaとGroovyを混在させていたか • もともとはJavaだけだった • 公式のプラグイン実装の書き方がGroovyで説明されていてJavaだと書きにくい ことがあった • Extension周りはGroovyで書いたほうがコードも短くなることがわかった
◦ Javaだとアクセッサの嵐になる • でもGroovyはIDEの対応が微妙で全部書き換える気になれなかった 14
#LOVE_KOTLIN 補足 ファイルサイズの変化 Java/Groovy (5.2.1): 圧縮後 85 KiB Kotlin (6.0.0-rc.2):
圧縮後 115KiB ソースコードの数はExtension用コード1つしか増えていないが、コンパイル後の classファイルが37から69に増えている。GroovyでもClosureごとにclassファイルを 作っていたが、KotlinになってLambdaがより増えた。 15