{"id":8412,"date":"2024-06-10T18:01:01","date_gmt":"2024-06-10T10:01:01","guid":{"rendered":""},"modified":"2024-06-10T18:01:01","modified_gmt":"2024-06-10T10:01:01","slug":"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8412.html","title":{"rendered":"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

2021\u5e74\uff0c\u5982\u4f55\u4f18\u96c5\u7684\u4f7f\u7528idea+Gradle\uff1f<\/h2>\n

Gradle + idea \u521d\u59cb\u5316\u914d\u7f6e<\/h3>\n

2021+\u7248\u672c\u7684ideaSetting...<\/code>\u5bf9Gradle\u7684\u8bbe\u7f6e\u4e0e2019\u5e74\u53ca\u4ee5\u524d\u7684\u7248\u672c\u9879\u76ee\u6709\u4e86\u5f88\u5927\u7684\u6539\u53d8\uff0c\u672c\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u5982\u4f55\u6b63\u786e\u7684\u5728\u65b0\u7248\u672c\u7684idea\u4e2d\u914d\u7f6eGradle\u7684\u4ed3\u5e93\u4f4d\u7f6e\u53ca\u4f18\u5148\u4f7f\u7528maven\u672c\u5730\u4ed3\u5e93\uff0c\u4ee5\u514d\u9020\u6210\u6570\u636e\u7684\u5197\u4f59\u3002\uff08\u5f3a\u8feb\u75c7\u72c2\u559c\uff09<\/p>\n

\u672c\u7bc7\u6587\u7ae0\u4f7f\u7528\u7684\u73af\u5883\uff1a \u64cd\u4f5c\u7cfb\u7edf\uff1aWindows 10 \u4e13\u4e1a\u7248 21H1 IntelliJ IDEA\u7248\u672c\uff1a 2021.1.3 (Ultimate Edition) JDK\u7248\u672c: 11.0.11+9-b1341.60 amd64 \uff08\u65e0\u9700\u4e0b\u8f7dGradle\uff0cidea\u81ea\u5e26Gradle\u63d2\u4ef6\uff0c\u6784\u5efa\u65f6\u9ed8\u8ba4\u4f7f\u7528\u6700\u65b0\u7a33\u5b9a\u7248\uff09 <\/code><\/pre>\n

\u4e0e\u4ee5\u524d\u7684\u7248\u672c\u76f8\u6bd4\uff0c\u9996\u5148\u662f\u754c\u9762\u7684\u4e0d\u540c\uff1a<\/p>\n

\"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

\u662f\u7684\u4f60\u6ca1\u770b\u9519\uff0cGeneral settings<\/code>\u53ea\u6709\u4e00\u4e2aGradle user home<\/code>\u3002\u5982\u679c\u4f60\u67e5\u8fc7\u5176\u4ed6\u8d44\u6599\uff0c\u5e94\u8be5\u4f1a\u60f3\u8d77\u73af\u5883\u53d8\u91cf\u7684\u914d\u7f6eGRADLE_USER_HOME<\/code>\u3002\u90a3\u4e48\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n

gradle user home<\/code>\u5176\u5b9e\u662fidea\u7684\u9879\u76ee\u4ece\u4e2d\u592e\u4ed3\u5e93\u4e0b\u8f7djar\u5305\u548cGradle\u73af\u5883\u8fd8\u6709\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u8fd9\u4e2a\u76ee\u5f55\u9ed8\u8ba4\u662f\u548cGRADLE_USER_HOME<\/code>\u540c\u6b65\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u5e76\u4e0d\u9700\u8981\u4fee\u6539gradle user home<\/code>\uff0c\u53ea\u9700\u8981\u5728\u73af\u5883\u53d8\u91cf\u4e2d\u52a0\u5165GRADLE_USER_HOME<\/code>\u5373\u53ef\u81ea\u52a8\u4fee\u6539gradle user home<\/code>\u3002<\/p>\n

\n

Tips\uff1agradle user home<\/code>\u7684\u9ed8\u8ba4\u8def\u5f84\u662f C:\\Users\\\u7528\u6237\u540d\\.Gradle<\/code>\uff0c\u4e5f\u5c31\u662f\u8bf4\u9ed8\u8ba4\u4e0b\u8f7d\u7684\u4f4d\u7f6e\u5c31\u662f\u8fd9\u91cc\uff0cC\u76d8\u7206\u70b8\u7684\u771f\u51f6\u627e\u5230\u4e86\uff01<\/p>\n

Tips 2\uff1a\u5f88\u591a\u6559\u7a0b\u4e2d\u63d0\u5230gradle user home<\/code>\u53ef\u4ee5\u88ab\u6539\u4e3a\u5b98\u7f51\u4e0b\u8f7d\u7684Gradle\u7a0b\u5e8f\u7684\u76ee\u5f55\uff0c\u5176\u5b9e\u8fd9\u6837\u505a\u5e76\u4e0d\u597d\u3002idea\u4f1a\u4f18\u5148\u4ecegradle user home<\/code>\u4e2d\u5bfb\u627e\u53ef\u6267\u884c\u7684gradle.bat\u7a0b\u5e8f\uff0c\u800c\u6211\u4eec\u81ea\u5df1\u8bbe\u7f6e\u7684Gradle\u53ef\u80fd\u4f1a\u4e0eproject\u9ed8\u8ba4\u7684gradle\u7a0b\u5e8f\u7684\u7248\u672c\u4e0d\u540c\uff0c\u8fd9\u5c06\u4f1a\u5bfc\u81f4\u4e00\u4e2aproject\u4e2d\u51fa\u73b0gradle\u5f02\u5e38\u7684\u60c5\u51b5\u3002\u5982\u4f55\u4f7f\u7528\u81ea\u5df1\u7684Gradle\u7a0b\u5e8f\u53c8\u4e0d\u4f1a\u4f7fproject\u7684Gradle\u7248\u672c\u51fa\u73b0\u9519\u8bef\uff0c\u89c1\u540e\u6587\u8be6\u89e3\u3002<\/p>\n<\/blockquote>\n

1.\u6dfb\u52a0GRADLE_USER_HOME<\/code><\/h5>\n

\u7efc\u4e0a\u6240\u8ff0\uff0c\u6211\u4eec\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6dfb\u52a0GRADLE_USER_HOME<\/code>\uff08Linux\u7cfb\u7edf\u8bf7\u81ea\u884c\u767e\u5ea6\uff0c\u672c\u7bc7\u4e0d\u518d\u8d58\u8ff0\uff09\uff1a<\/p>\n

1.\u6253\u5f00\u201c\u8bbe\u7f6e\u201d\uff0c\u9009\u62e9\u201c\u7cfb\u7edf\u201d<\/p>\n

\"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

2.\u62c9\u5230\u6700\u4e0b\u9762\u7684\u5173\u4e8e\uff0c\u9009\u62e9\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e<\/h5>\n

\"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

3.\u9009\u62e9\u53f3\u4e0b\u89d2\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d -> \u201c\u65b0\u5efa\u201d -> \u53d8\u91cf\u540d\u4e3aGRADLE_USER_HOME<\/code>\uff0c\u503c\u5373\u4e3a\u4f60\u60f3\u4fdd\u5b58\u7684\u76ee\u5f55\u8def\u5f84\u3002<\/h5>\n

\"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

\u8fd9\u6837\u5c31\u914d\u7f6e\u597d\u4e86\u6211\u4eec\u7684\u4e0b\u8f7d\u76ee\u5f55\u4e86\u3002\u6253\u5f00idea\uff0c\u65b0\u5efa\u4e00\u4e2aproject\u6d4b\u8bd5\u4e00\u4e0b\u3002<\/p>\n

\"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684Gradle project\u540e\uff0c\u6211\u4eec\u5148\u524d\u8bbe\u7f6e\u7684\u76ee\u5f55D:\\Maven\\Gradle<\/code>\u81ea\u52a8\u751f\u6210\u4e86\u8bb8\u591a\u6587\u4ef6\u5939\uff0c\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\uff1a<\/p>\n

.\\caches\\modules-2\\files-2.1 \u4e2d\u5b58\u653e\u4e86\u6211\u4eec\u4ece\u4e2d\u592e\u4ed3\u5e93\u6240\u4e0b\u8f7d\u7684jar\u5305 .\\wrapper\\dists \u4e2d\u5b58\u653e\u7684\u662fGradle \u7a0b\u5e8f\uff08\u8fd9\u4e5f\u662f\u6211\u8bf4\u4e0d\u9700\u8981\u81ea\u5df1\u4e0b\u7684\u539f\u56e0\uff0cidea\u4f1a\u4e3b\u52a8\u5e2e\u6211\u4eec\u4e0b\u597d\uff09 <\/code><\/pre>\n

\u4fee\u6539\u5b8c\u4f4d\u7f6e\uff0c\u521b\u5efa\u5b8cnew project\uff0c\u4f60\u53ef\u80fd\u53d1\u73b0\u4e86\u2014\u2014\u600e\u4e48\u4e0b\u5305\u8fd9\u4e48\u6162\uff0c\u6211\u8981\u914d\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\uff01\u4f46\u4e00\u4e2a\u4e2aproject\u7684build.gradle\u6539\u592a\u6162\u4e86\uff0c\u8ba9\u6211\u4eec\u4f7f\u7528\u76f8\u5f53\u4e8emaven\u7684settings.xml<\/code>\u4e00\u6837\u7684init.gradle<\/code>\u5427\uff01<\/p>\n

init.gradle \u914d\u7f6e\u5168\u5c40\u4ed3\u5e93<\/h3>\n

init.gradle<\/code>\u76f8\u5f53\u4e8emaven\u4e2d\u7684settings.xml<\/code>\uff0c\u56e0\u6b64\u5b83\u4e5f\u662f\u6709\u52a0\u8f7d\u987a\u5e8f\u7684\uff1a<\/p>\n

    \n
  1. ~\/.gradle\/init.gradle\u6587\u4ef6<\/code><\/li>\n
  2. ~\/.gradle\/init.d\/\u76ee\u5f55\u4e0b\u7684\u4ee5.gradle\u7ed3\u5c3e\u7684\u6587\u4ef6<\/code><\/li>\n
  3. GRADLE_HOME\/init.d\/\u76ee\u5f55\u4e0b\u7684\u4ee5.gradle\u7ed3\u5c3e\u7684\u6587\u4ef6<\/code><\/li>\n
  4. GRADLE_USER_HOME\/init.gradle\u6587\u4ef6<\/code><\/li>\n
  5. GRADLE_USER_HOME\/init.d\u76ee\u5f55\u4e0b\u7684\u4ee5.gradle\u7ed3\u5c3e\u7684\u6587\u4ef6<\/code><\/li>\n<\/ol>\n
    \n

    \u8fd9\u91cc\u7684GRADLE_HOME<\/code>\u548c GRADLE_USER_HOME<\/code>\u90fd\u662f\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\uff0cGRADLE_HOME<\/code>\u5c31\u662fGradle\u5b89\u88c5\u7684\u4f4d\u7f6e\uff0c<\/p>\n

    ~<\/code>\u76f8\u5f53\u4e8eC:\\Users\\Holme\\\u7528\u6237\u540d<\/code>\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0a\u9762\u7684\u5185\u5bb9\u662flinux\/windows\u901a\u7528\u3002<\/p>\n<\/blockquote>\n

    \u6211\u4eec\u4e4b\u524d\u5df2\u7ecf\u914d\u7f6e\u4e86GRADLE_USER_HOME<\/code>\uff0c\u56e0\u6b64\u5c31\u5728D:\\Maven\\Gradle<\/code>\u76ee\u5f55\u4e0b\u65b0\u5efainit.gradle<\/code>\u6587\u4ef6\uff1a<\/p>\n

    allprojects { \n   <\/span> repositories { \n   <\/span> maven { \n   <\/span> url 'https:\/\/maven.aliyun.com\/repository\/gradle-plugin'<\/span> }<\/span> maven { \n   <\/span> url 'https:\/\/maven.aliyun.com\/repository\/google'<\/span> }<\/span> maven { \n   <\/span> url 'https:\/\/maven.aliyun.com\/nexus\/content\/groups\/public\/'<\/span> }<\/span> maven { \n   <\/span> url 'https:\/\/maven.aliyun.com\/repository\/jcenter'<\/span> }<\/span> mavenCentral<\/span>(<\/span>)<\/span> }<\/span> }<\/span> <\/code><\/pre>\n

    \u8fd9\u6bb5\u4ee3\u7801\u8868\u793a\u6211\u4eec\u5c06aliyun\u7684\u51e0\u4e2amaven\u4ed3\u5e93\u4f5c\u4e3a\u6211\u4eec\u7684\u9996\u9009\u4e0b\u8f7d\u5730\u5740\uff0c\u5982\u679c\u8fd9\u56db\u4e2a\u5730\u5740\u90fd\u627e\u4e0d\u5230\uff0c\u5219\u8c03\u7528 mavenCentral()<\/code>\u65b9\u6cd5\u4ecemaven\u4e2d\u592e\u4ed3\u5e93\u4e2d\u5bfb\u627ejar\u5305\u3002\uff08\u56e0\u6b64Gradle\u67e5\u627e\u4ed3\u5e93\u7684\u987a\u5e8f\u662f\u4ece\u4e0a\u5f80\u4e0b\uff09<\/p>\n

    \u4f7f\u7528\u672c\u5730maven\u4ed3\u5e93\u4f5c\u4e3a\u6211\u4eec\u7684\u9996\u9009\u4ed3\u5e93<\/h5>\n

    \u5927\u5bb6\u5b66\u4e60Gradle\u65f6\u57fa\u672c\u4e0a\u5df2\u7ecf\u5b66\u4e60\u8fc7maven\u4e86\uff0c\u56e0\u6b64\u5728\u672c\u5730\u80af\u5b9a\u4e5f\u6709\u5c5e\u4e8e\u81ea\u5df1\u7684maven\u4ed3\u5e93\u3002\uff08\u6ca1\u5b66\u8fc7\u7684\u53ef\u4ee5\u770b\u6211\u7684\u6587\u7ae0\u5b66\u4e60\u4e00\u4e0b\u5982\u4f55\u4f18\u96c5\u5730\u4f7f\u7528idea+maven\uff09<\/p>\n

    \u6211\u4eec\u53ea\u9700\u8981\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u884cmavenLocal()<\/code>\u5373\u53ef\uff1a<\/p>\n

    repositories { \n   <\/span> mavenLocal<\/span>(<\/span>)<\/span> }<\/span> <\/code><\/pre>\n

    \u4f46\u6211\u4eec\u8fd8\u4e0d\u77e5\u9053Gradle\u77e5\u4e0d\u77e5\u9053\u6211\u4eec\u672c\u5730\u4ed3\u5e93\u7684\u4f4d\u7f6e\u5728\u54ea\u5440\uff1f\uff01\uff08\u6709\u70b9\u7ed5\uff09\u4e0d\u7740\u6025\uff0c\u6211\u4eec\u5148\u6765\u770b\u770bGradle\u67e5\u627e\u672c\u5730\u4ed3\u5e93\u4f4d\u7f6e\u7684\u8fc7\u7a0b\uff1a<\/p>\n

      \n
    1. ~\/.m2\/settings.xml<\/code><\/li>\n
    2. M2_HOME\/conf\/settings.xml<\/code><\/li>\n
    3. ~\/.m2\/repository<\/code><\/li>\n<\/ol>\n
      \n

      \u8fd9\u91cc\u7684 M2_HOME<\/code>\u662f\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\uff0c\u4e5f\u5c31\u662fmaven\u7684\u5b89\u88c5\u76ee\u5f55\u3002<\/p>\n<\/blockquote>\n

      \u770b\u5230\u8fd9\u91cc\u4f60\u662f\u4e0d\u662f\u5df2\u7ecf\u604d\u7136\u5927\u609f\u4e86\u5462\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4fee\u6539settings.xml\u6587\u4ef6\u6216\u8005\u76f4\u63a5\u4f7f\u7528\u9ed8\u8ba4\u8bbe\u7f6e\u5373\u53ef\u3002\u8fd9\u91cc\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0bsettings.xml\u6587\u4ef6\u8be5\u5982\u4f55\u914d\u7f6e\u3002<\/p>\n

      <?xml version=\"1.0\" encoding=\"UTF-8\"?><\/span> <<\/span>settings<\/span> xmlns<\/span>=<\/span>\"<\/span>http:\/\/maven.apache.org\/SETTINGS\/1.0.0\"<\/span><\/span> xmlns:<\/span>xsi<\/span>=<\/span>\"<\/span>http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span><\/span> xsi:<\/span>schemaLocation<\/span>=<\/span>\"<\/span>http:\/\/maven.apache.org\/SETTINGS\/1.0.0 http:\/\/maven.apache.org\/xsd\/settings-1.0.0.xsd\"<\/span><\/span>><\/span><\/span> <<\/span>localRepository<\/span>><\/span><\/span>D:\\Maven\\repository<\/<\/span>localRepository<\/span>><\/span><\/span> <\/<\/span>settings<\/span>><\/span><\/span> <\/code><\/pre>\n

      \u524d\u9762\u4e00\u5806\u7ea6\u675f\u5e76\u4e0d\u91cd\u8981\uff0c\u91cd\u70b9\u5c31\u662f<localRepository>D:\\Maven\\repository<\/localRepository><\/code>\u8fd9\u4e2a\u6807\u7b7e\uff0c\u5c06\u6807\u7b7e\u5185\u5bb9\u6362\u6210\u4f60\u7684maven repository\u5730\u5740\u5373\u53ef\u3002<\/p>\n

      \u81f3\u6b64\uff0c\u4f60\u5b8c\u6210\u7684idea+Gradle \u7684\u57fa\u672c\u914d\u7f6e\u3002<\/p>\n

      \u5982\u4f55\u5728\u9879\u76ee\u4e2d\u6307\u5b9aGradle\u7a0b\u5e8f\u7684\u4f4d\u7f6e\uff1f<\/h4>\n

      \u8ba9\u6211\u4eec\u6253\u5f00\u4e00\u4e2aproject\uff0c\u518d\u6253\u5f00settings\uff0c\u8fdb\u5165Gradle\u7684settings\u3002<\/p>\n

      \"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

      \u6211\u4eec\u53d1\u73b0\u754c\u9762\u548c\u4e4b\u524d\u4e0d\u592a\u4e00\u6837\uff0c\u7ea2\u8272\u5708\u8d77\u6765\u7684User Gradle from<\/code>\u8bbe\u7f6e\u53ef\u4ee5\u8ba9\u6211\u4eec\u914d\u7f6e\u81ea\u5df1\u7684Gradle\u7a0b\u5e8f\u76ee\u5f55\uff1a<\/p>\n

      \"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle<\/p>\n

      \u9009\u62e9Specified location<\/code>\uff0c\u5e76\u5728\u53f3\u8fb9\u9009\u62e9\u4f60\u7684Gradle\u76ee\u5f55\u8def\u5f84\uff0c\u5373\u53ef\u9009\u62e9\u4f60\u81ea\u5df1\u7684Gradle\u7a0b\u5e8f\u3002\u53ea\u8981 Gradle User home<\/code>\u4e0d\u53d8\uff0c\u4e0b\u8f7d\u7684\u76ee\u5f55\u4f9d\u7136\u662f\u6211\u4eec\u5728\u73af\u5883\u53d8\u91cf\u4e2d\u8bbe\u7f6e\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u4ea7\u751fGradle\u7248\u672c\u51b2\u7a81\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u600e\u6837\u4f7f\u7528idea_idea\u600e\u4e48\u914d\u7f6egradle2021\u5e74\uff0c\u5982\u4f55\u4f18\u96c5\u7684\u4f7f\u7528idea+Gradle\uff1fGradle+idea\u521d\u59cb\u5316\u914d\u7f6e2021+\u7248\u672c\u7684ideaSetting...\u5bf9Gra...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8412"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8412"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8412\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}