{"id":503590,"date":"2024-08-16T04:25:07","date_gmt":"2024-08-16T03:25:07","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=idea&#038;p=503590"},"modified":"2024-08-16T04:40:20","modified_gmt":"2024-08-16T03:40:20","slug":"meet-the-renovated-kotlin-support-k2-mode","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/zh-hans\/idea\/2024\/08\/meet-the-renovated-kotlin-support-k2-mode\/","title":{"rendered":"\u8fce\u63a5\u5168\u65b0\u7684 Kotlin \u652f\u6301 \u2013 K2 \u6a21\u5f0f\uff1a\u57fa\u672c\u4fe1\u606f"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u6536\u96c6\u4e86\u6709\u5173 IntelliJ IDEA \u4e2d K2 \u6a21\u5f0f\u7684\u57fa\u672c\u4fe1\u606f\u3002<\/p>\n<h2 class=\"wp-block-heading\">K2 \u6a21\u5f0f\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f<\/h2>\n<p>K2 \u6a21\u5f0f\u662f IntelliJ IDEA \u4e2d Kotlin \u652f\u6301\u7684\u65b0\u5b9e\u73b0\uff0c\u5b83\u53ef\u4ee5\u63d0\u9ad8 IDE \u7684\u7a33\u5b9a\u6027\uff0c\u540c\u65f6\u4e5f\u4f1a\u4e3a\u652f\u6301\u672a\u6765 Kotlin \u8bed\u8a00\u529f\u80fd\u5960\u5b9a\u57fa\u7840\u3002<\/p>\n<h2 class=\"wp-block-heading\">K2 \u6a21\u5f0f\u4e0e Kotlin K2 \u7f16\u8bd1\u5668\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h2>\n<p>K2 \u7f16\u8bd1\u5668\u8d1f\u8d23\u7f16\u8bd1 Kotlin \u8bed\u8a00 2.0 \u6216\u66f4\u9ad8\u7248\u672c\u7684 Kotlin \u4ee3\u7801\u3002 \u5982\u679c\u60a8\u60f3\u4f7f\u7528 K2 \u7f16\u8bd1\u5668\u7f16\u8bd1\u9879\u76ee\uff0c\u60a8\u9700\u8981\u5728\u9879\u76ee\u7684\u6784\u5efa\u8bbe\u7f6e\uff08\u5728 <code>build.gradle.kts<\/code> \u6216 <code>pom.xml<\/code> \u6587\u4ef6\u4e2d\uff09\u4e2d\u6307\u5b9a Kotlin 2.0 \u8bed\u8a00\u7248\u672c\u3002<\/p>\n<p>K2 \u6a21\u5f0f\u4e0d\u4f9d\u8d56\u4e8e\u9879\u76ee\u6784\u5efa\u8bbe\u7f6e\u4e2d\u6307\u5b9a\u7684 Kotlin \u7f16\u8bd1\u5668\u7248\u672c\u3002 K2 \u6a21\u5f0f\u7ecf\u8fc7\u4e13\u95e8\u8bbe\u8ba1\uff0c\u53ef\u4ee5\u5229\u7528 K2 \u7f16\u8bd1\u5668\u7684\u9ad8\u7ea7\u529f\u80fd\u5b9e\u73b0\u66f4\u5feb\u3001\u66f4\u53ef\u9760\u7684 Kotlin \u4ee3\u7801\u5206\u6790\u3002 IntelliJ IDEA \u4e2d\u7684 K2 \u6a21\u5f0f<strong>\u4ec5<\/strong>\u5f71\u54cd\u4ee3\u7801\u9ad8\u4eae\u663e\u793a\u3001\u4ee3\u7801\u8865\u5168\u548c\u5176\u4ed6 IDE \u529f\u80fd\u3002<\/p>\n<h2 class=\"wp-block-heading\">K2 \u6a21\u5f0f\u76ee\u524d\u652f\u6301\u54ea\u4e9b\u529f\u80fd\uff1f<\/h2>\n<p>\u4ece IntelliJ IDEA 2024.2 \u5f00\u59cb\uff0cK2 \u6a21\u5f0f\u652f\u6301\u7edd\u5927\u591a\u6570 IDE \u529f\u80fd\uff0c\u5305\u62ec <code>build.gradle.kts<\/code> \u811a\u672c\u3001Kotlin Multiplatform (KMP) \u9879\u76ee\u3001\u5927\u591a\u6570\u91cd\u6784\u3001\u4ee3\u7801\u9ad8\u4eae\u663e\u793a\u3001\u8865\u5168\u3001\u8c03\u8bd5\u7b49\u3002<\/p>\n<p>\u5bf9 Kotlin\/Wasm\u3001\u4e34\u65f6\u6587\u4ef6\u548c\u4e0d\u592a\u5e38\u7528\u7684\u91cd\u6784\u7684\u652f\u6301\u5c06\u5f88\u5feb\u6dfb\u52a0\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u542f\u7528 K2 \u6a21\u5f0f\uff1f<\/h2>\n<p>\u8981\u542f\u7528 K2 \u6a21\u5f0f\uff0c\u8bf7\u8f6c\u5230 <em>Preferences\/Settings | Languages &amp; Frameworks | Kotlin<\/em>\uff08\u504f\u597d\u8bbe\u7f6e\/\u8bbe\u7f6e | \u8bed\u8a00\u548c\u6846\u67b6 | Kotlin\uff09\u5e76\u52fe\u9009 <em>Enable K2 Kotlin Mode<\/em>\uff08\u542f\u7528 K2 Kotlin \u6a21\u5f0f\uff09\u590d\u9009\u6846\u3002<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-498386\" style=\"aspect-ratio: 3.45; width: 629px; height: auto;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/08\/Enable-K2-mode-IntelliJ-IDEA.png\" alt=\"\" width=\"1104\" height=\"320\" \/><\/figure>\n<h2 class=\"wp-block-heading\">\u54ea\u4e9b IntelliJ IDEA \u548c Kotlin \u7248\u672c\u4e0e K2 \u6a21\u5f0f\u517c\u5bb9\uff1f<\/h2>\n<p>K2 \u6a21\u5f0f\u4e0e Kotlin 1.9 \u53ca\u66f4\u9ad8\u7248\u672c\u517c\u5bb9\u3002 \u5b83\u4e0e v2024.1 \u53ca\u4e4b\u540e\u7684 IntelliJ IDEA \u96c6\u6210\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-498375\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/08\/K2-mode.png\" alt=\"K2 \u6a21\u5f0f IntelliJ IDEA \u517c\u5bb9\u6027\u56fe\u8868\" width=\"3840\" height=\"2160\" \/><\/figure>\n<h2 class=\"wp-block-heading\">K2 \u6a21\u5f0f\u4f1a\u7834\u574f\u6216\u5f71\u54cd\u6211\u7684\u4ee3\u7801\u5417\uff1f<\/h2>\n<p>IntelliJ IDEA \u4e2d\u7684 K2 \u6a21\u5f0f\u4e0d\u4f1a\u5f71\u54cd\u4ee3\u7801\u7f16\u8bd1\uff0c\u53ea\u5f71\u54cd IDE \u4e2d\u7684\u4ee3\u7801\u5206\u6790\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48 IntelliJ IDEA \u4f1a\u8fd4\u56de\u201cplugin is incompatible with K2 mode\u201d\uff08\u63d2\u4ef6\u4e0e K2 \u6a21\u5f0f\u4e0d\u517c\u5bb9\uff09\u9519\u8bef\uff1f<\/h2>\n<p>\u7531\u4e8e Kotlin Plugin API \u7684\u6700\u65b0\u66f4\u6539\uff0c\u67d0\u4e9b\u7b2c\u4e09\u65b9 IntelliJ IDEA \u63d2\u4ef6\u76ee\u524d\u53ef\u80fd\u4e0d\u53ef\u7528\u3002 \u6211\u4eec\u6b63\u5728\u79ef\u6781\u534f\u52a9\u63d2\u4ef6\u4f5c\u8005\u6765\u5c3d\u5feb\u4f7f\u5176\u63d2\u4ef6\u4e0e K2 \u6a21\u5f0f\u517c\u5bb9\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u548c\u6211\u4eec\u4e00\u8d77\u5851\u9020 K2 \u6a21\u5f0f\uff01<\/h2>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f\u5728\u4eca\u5e74\u5e74\u5e95\u4e4b\u524d\u4ece IntelliJ IDEA 2024.3 \u5f00\u59cb\u9ed8\u8ba4\u542f\u7528 K2 \u6a21\u5f0f\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u60a8\u7684\u53cd\u9988\uff01<\/p>\n<p>\u5e2e\u52a9\u6211\u4eec\u5c06 K2 \u6a21\u5f0f\u6539\u8fdb\u5230\u6700\u4f73\u72b6\u6001\u3002 \u8bf7\u5728\u6211\u4eec\u7684<a href=\"https:\/\/kotlinlang.slack.com\/archives\/C0B8H786P\" target=\"_blank\" rel=\"noopener\">\u516c\u5171 Slack \u9891\u9053<\/a>\u6216\u901a\u8fc7 <a href=\"https:\/\/youtrack.jetbrains.com\/issues\/KTIJ?u=1\" target=\"_blank\" rel=\"noopener\">YouTrack<\/a> \u5206\u4eab\u60a8\u7684\u4f53\u9a8c\u3002<\/p>\n<p>\u795d\u60a8\u5f00\u53d1\u6109\u5feb\uff01<\/p>\n<\/p>\n<p>\u672c\u535a\u6587\u82f1\u6587\u539f\u4f5c\u8005\uff1a<\/p>\n\n    <div class=\"about-author \">\n        <div class=\"about-author__box\">\n            <div class=\"row\">\n                <div class=\"about-author__box-img\">\n                    <img decoding=\"async\" src=\"https:\/\/secure.gravatar.com\/avatar\/?s=200&#038;r=g\" width=\"200\" height=\"200\" alt=\"\" loading=\"lazy\"  class=\"avatar avatar-200 wp-user-avatar wp-user-avatar-200 photo avatar-default\">\n                <\/div>\n                <div class=\"about-author__box-text\">\n                                                        <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n","protected":false},"author":1297,"featured_media":498529,"comment_status":"closed","ping_status":"closed","template":"","categories":[89],"tags":[21],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/503590"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/types\/idea"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/users\/1297"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=503590"}],"version-history":[{"count":10,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/503590\/revisions"}],"predecessor-version":[{"id":503760,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/503590\/revisions\/503760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media\/498529"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=503590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=503590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=503590"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/cross-post-tag?post=503590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}