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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
200
AI といっしょに仕事をする(子供向け)
eller86
0
49
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
200
生成AI 業務応用向けガイドライン 斜め読み / Overview of Generative AI Business Application Guidelines
eller86
0
220
KotlinユーザのためのJSpecify入門 / JSpecify 101 for Kotlin Devs
eller86
0
2.4k
ヒューマンスキル / The Humanskills
eller86
0
780
医療機関向けシステムの信頼性 / Reliability of systems for medical institutions
eller86
0
550
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.2k
Other Decks in Programming
See All in Programming
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
430
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
200
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
720
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
260
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.2k
アクセシビリティから考える情報設計
high_g_engineer
0
380
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
190
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
390
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
200
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
320
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
130
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Optimising Largest Contentful Paint
csswizardry
37
4k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
280
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
420
Un-Boring Meetings
codingconduct
0
420
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
Skip the Path - Find Your Career Trail
mkilby
1
230
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